def test_verbose_description(self): matchee = 2 matcher = Equals(3) mismatch = matcher.match(2) e = MismatchError(matchee, matcher, mismatch, True) expected = ('Match failed. Matchee: %r\n' 'Matcher: %s\n' 'Difference: %s\n' % ( matchee, matcher, matcher.match(matchee).describe(), )) self.assertEqual(expected, str(e))
def test_verbose_unicode(self): # When assertThat is given matchees or matchers that contain non-ASCII # unicode strings, we can still provide a meaningful error. matchee = '\xa7' matcher = Equals('a') mismatch = matcher.match(matchee) expected = ('Match failed. Matchee: %s\n' 'Matcher: %s\n' 'Difference: %s\n' % ( text_repr(matchee), matcher, mismatch.describe(), )) e = MismatchError(matchee, matcher, mismatch, True) self.assertEqual(expected, str(e))
def test_verbose_unicode(self): # When assertThat is given matchees or matchers that contain non-ASCII # unicode strings, we can still provide a meaningful error. matchee = _u('\xa7') matcher = Equals(_u('a')) mismatch = matcher.match(matchee) expected = ('Match failed. Matchee: %s\n' 'Matcher: %s\n' 'Difference: %s\n' % ( text_repr(matchee), matcher, mismatch.describe(), )) e = MismatchError(matchee, matcher, mismatch, True) if str_is_unicode: actual = str(e) else: actual = unicode(e) # Using str() should still work, and return ascii only self.assertEqual( expected.replace(matchee, matchee.encode("unicode-escape")), str(e).decode("ascii")) self.assertEqual(expected, actual)
def test_default_description_unicode(self): matchee = '\xa7' matcher = Equals('a') mismatch = matcher.match(matchee) e = MismatchError(matchee, matcher, mismatch) self.assertEqual(mismatch.describe(), str(e))
def test_default_description_is_mismatch(self): mismatch = Equals(3).match(2) e = MismatchError(2, Equals(3), mismatch) self.assertEqual(mismatch.describe(), str(e))
def raise_mismatch_error(): raise MismatchError(2, Equals(3), Equals(3).match(2))