def text_content(text): """Create a `Content` object from some text. This is useful for adding details which are short strings. """ if _isbytes(text): raise TypeError('text_content must be given a string, not bytes.') return Content(UTF8_TEXT, lambda: [text.encode('utf8')])
def __str__(self): difference = self.mismatch.describe() if self.verbose: # GZ 2011-08-24: Smelly API? Better to take any object and special # case text inside? if istext(self.matchee) or _isbytes(self.matchee): matchee = text_repr(self.matchee, multiline=False) else: matchee = repr(self.matchee) return "Match failed. Matchee: %s\nMatcher: %s\nDifference: %s\n" % (matchee, self.matcher, difference) else: return difference
def __str__(self): difference = self.mismatch.describe() if self.verbose: # GZ 2011-08-24: Smelly API? Better to take any object and special # case text inside? if istext(self.matchee) or _isbytes(self.matchee): matchee = text_repr(self.matchee, multiline=False) else: matchee = repr(self.matchee) return ( 'Match failed. Matchee: %s\nMatcher: %s\nDifference: %s\n' % (matchee, self.matcher, difference)) else: return difference
def _format(self, thing): # Blocks of text with newlines are formatted as triple-quote # strings. Everything else is pretty-printed. if istext(thing) or _isbytes(thing): return text_repr(thing) return pformat(thing)