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)
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)
def test_parse_override_default(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type( 'text/plain; face=ouch', default_charset='latin-1'))
def test_parse_nocharset_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type( 'text/plain; face=ouch'))
def test_parse_error_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type( 'text/plain; face=ouch; charset=latin-1;'))
def test_parse_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type('text/plain'))
def test_parse_extra(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type( 'text/plain; charset=latin-1; version=1.2'))
def test_parse_simple(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type('text/plain; charset=latin-1'))
def test_parse_override_default(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type( 'text/plain; face=ouch', default_charset='latin-1'))
def test_parse_nocharset_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type( 'text/plain; face=ouch'))
def test_parse_error_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type( 'text/plain; face=ouch; charset=latin-1;'))
def test_parse_default(self): self.assertEqual( ('text/plain', 'utf-8'), utils.parse_content_type('text/plain'))
def test_parse_extra(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type( 'text/plain; charset=latin-1; version=1.2'))
def test_parse_simple(self): self.assertEqual( ('text/plain', 'latin-1'), utils.parse_content_type('text/plain; charset=latin-1'))