コード例 #1
0
    def assert_in_or_print_output(self, expected, iterable):
        """Assert the iterable contains expected or print some output.

        If the output is long, it is limited by either GABBI_MAX_CHARS_OUTPUT
        in the environment or the MAX_CHARS_OUTPUT constant.
        """
        if utils.not_binary(utils.parse_content_type(self.content_type)[0]):
            if expected in iterable:
                return

            if self.response_data:
                dumper_class = self.get_content_handler(self.content_type)
                if dumper_class:
                    full_response = dumper_class.dumps(self.response_data,
                                                       pretty=True)
                else:
                    full_response = self.output
            else:
                full_response = self.output

            max_chars = os.getenv('GABBI_MAX_CHARS_OUTPUT', MAX_CHARS_OUTPUT)
            response = full_response[0:max_chars]
            is_truncated = (len(response) != len(full_response))

            if iterable == self.output:
                msg = "'%s' not found in %s%s" % (expected, response,
                                                  '\n...truncated...'
                                                  if is_truncated else '')
            else:
                msg = "'%s' not found in %s, %sresponse:\n%s" % (
                    expected, iterable, 'truncated ' if is_truncated else '',
                    response)
            self.fail(msg)
        else:
            self.assertIn(expected, iterable)
コード例 #2
0
ファイル: case.py プロジェクト: cdent/gabbi
    def assert_in_or_print_output(self, expected, iterable):
        """Assert the iterable contains expected or print some output.

        If the output is long, it is limited by either GABBI_MAX_CHARS_OUTPUT
        in the environment or the MAX_CHARS_OUTPUT constant.
        """
        if utils.not_binary(utils.parse_content_type(self.content_type)[0]):
            if expected in iterable:
                return

            if self.response_data:
                dumper_class = self.get_content_handler(self.content_type)
                if dumper_class:
                    full_response = dumper_class.dumps(self.response_data,
                                                       pretty=True, test=self)
                else:
                    full_response = self.output
            else:
                full_response = self.output

            max_chars = os.getenv('GABBI_MAX_CHARS_OUTPUT', MAX_CHARS_OUTPUT)
            response = full_response[0:max_chars]
            is_truncated = (len(response) != len(full_response))

            if iterable == self.output:
                msg = "'%s' not found in %s%s" % (
                    expected, response,
                    '\n...truncated...' if is_truncated else ''
                )
            else:
                msg = "'%s' not found in %s, %sresponse:\n%s" % (
                    expected, iterable,
                    'truncated ' if is_truncated else '',
                    response)
            self.fail(msg)
        else:
            self.assertIn(expected, iterable)
コード例 #3
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_override_default(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type(
             'text/plain; face=ouch', default_charset='latin-1'))
コード例 #4
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_nocharset_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type(
             'text/plain; face=ouch'))
コード例 #5
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_error_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type(
             'text/plain; face=ouch; charset=latin-1;'))
コード例 #6
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type('text/plain'))
コード例 #7
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_extra(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type(
             'text/plain; charset=latin-1; version=1.2'))
コード例 #8
0
ファイル: test_utils.py プロジェクト: cdent/gabbi
 def test_parse_simple(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type('text/plain; charset=latin-1'))
コード例 #9
0
 def test_parse_override_default(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type(
             'text/plain; face=ouch', default_charset='latin-1'))
コード例 #10
0
 def test_parse_nocharset_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type(
             'text/plain; face=ouch'))
コード例 #11
0
 def test_parse_error_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type(
             'text/plain; face=ouch; charset=latin-1;'))
コード例 #12
0
 def test_parse_default(self):
     self.assertEqual(
         ('text/plain', 'utf-8'),
         utils.parse_content_type('text/plain'))
コード例 #13
0
 def test_parse_extra(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type(
             'text/plain; charset=latin-1; version=1.2'))
コード例 #14
0
 def test_parse_simple(self):
     self.assertEqual(
         ('text/plain', 'latin-1'),
         utils.parse_content_type('text/plain; charset=latin-1'))