Exemple #1
0
 def test_long_unicode(self):
     one_line_u = self._long_u.replace("\n", " ")
     mismatch = _BinaryMismatch(one_line_u, "!~", self._long_u)
     self.assertEqual(
         mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
         ("!~", text_repr(one_line_u),
          text_repr(self._long_u, multiline=True)))
Exemple #2
0
 def test_describe_non_ascii_unicode(self):
     string = _u("A\xA7")
     suffix = _u("B\xA7")
     mismatch = DoesNotEndWith(string, suffix)
     self.assertEqual(
         "%s does not end with %s." %
         (text_repr(string), text_repr(suffix)), mismatch.describe())
Exemple #3
0
 def test_long_unicode(self):
     one_line_u = self._long_u.replace("\n", " ")
     mismatch = _BinaryMismatch(one_line_u, "!~", self._long_u)
     self.assertEqual(mismatch.describe(),
         "%s:\nreference = %s\nactual    = %s\n" % ("!~",
             text_repr(one_line_u),
             text_repr(self._long_u, multiline=True)))
Exemple #4
0
 def test_long_bytes(self):
     one_line_b = self._long_b.replace(_b("\n"), _b(" "))
     mismatch = _BinaryMismatch(one_line_b, "!~", self._long_b)
     self.assertEqual(
         mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
         ("!~", text_repr(one_line_b),
          text_repr(self._long_b, multiline=True)))
Exemple #5
0
 def test_long_mixed_strings(self):
     mismatch = _BinaryMismatch(self._long_b, "!~", self._long_u)
     self.assertEqual(
         mismatch.describe(),
         "%s:\nreference = %s\nactual    = %s\n"
         % ("!~", text_repr(self._long_b, multiline=True), text_repr(self._long_u, multiline=True)),
     )
Exemple #6
0
 def test_describe_non_ascii_unicode(self):
     string = _u("A\xA7")
     suffix = _u("B\xA7")
     mismatch = DoesNotEndWith(string, suffix)
     self.assertEqual("%s does not end with %s." % (
         text_repr(string), text_repr(suffix)),
         mismatch.describe())
Exemple #7
0
 def test_long_bytes(self):
     one_line_b = self._long_b.replace(_b("\n"), _b(" "))
     mismatch = _BinaryMismatch(one_line_b, "!~", self._long_b)
     self.assertEqual(mismatch.describe(),
         "%s:\nreference = %s\nactual    = %s\n" % ("!~",
             text_repr(one_line_b),
             text_repr(self._long_b, multiline=True)))
Exemple #8
0
 def test_long_mixed_strings(self):
     mismatch = _BinaryMismatch(self._long_b, "!~", self._long_u)
     self.assertEqual(
         mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" % (
             "!~",
             text_repr(self._long_u, multiline=True),
             text_repr(self._long_b, multiline=True),
         ))
Exemple #9
0
 def test_describe_non_ascii_unicode(self):
     string = "A\xA7"
     suffix = "B\xA7"
     mismatch = DoesNotEndWith(string, suffix)
     self.assertEqual(
         "{} does not end with {}.".format(text_repr(string),
                                           text_repr(suffix)),
         mismatch.describe())
Exemple #10
0
 def test_long_unicode_and_object(self):
     obj = object()
     mismatch = _BinaryMismatch(self._long_u, "!~", obj)
     self.assertEqual(mismatch.describe(),
         "%s:\nreference = %s\nactual    = %s\n" % ("!~",
             text_repr(self._long_u, multiline=True),
             repr(obj)))
Exemple #11
0
 def test_ascii_examples_oneline_bytes(self):
     for s, expected, _ in self.ascii_examples:
         b = _b(s)
         actual = text_repr(b, multiline=False)
         # Add self.assertIsInstance check?
         self.assertEqual(actual, self.b_prefix + expected)
         self.assertEqual(eval(actual), b)
Exemple #12
0
 def test_long_unicode_and_object(self):
     obj = object()
     mismatch = _BinaryMismatch(self._long_u, "!~", obj)
     self.assertEqual(
         mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" % (
             "!~",
             repr(obj),
             text_repr(self._long_u, multiline=True),
         ))
Exemple #13
0
 def test_long_bytes_and_object(self):
     obj = object()
     mismatch = _BinaryMismatch(self._long_b, "!~", obj)
     self.assertEqual(
         mismatch.describe(),
         "{}:\nreference = {}\nactual    = {}\n".format(
             "!~",
             repr(obj),
             text_repr(self._long_b, multiline=True),
         ))
Exemple #14
0
 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
Exemple #15
0
 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
Exemple #16
0
 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))
Exemple #17
0
 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_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)
Exemple #19
0
 def describe(self):
     return "%s does not comply with schema %s. msg: %s" % (
         text_repr(str(self.json)),
         text_repr(str(self.schema)),
         text_repr(self.err_msg),
     )
Exemple #20
0
 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)
Exemple #21
0
 def describe(self):
     return "%s does not end with %s." % (text_repr(
         self.matchee), text_repr(self.expected))
Exemple #22
0
 def test_ascii_examples_multiline_unicode(self):
     for s, _, expected in self.ascii_examples:
         actual = text_repr(s, multiline=True)
         self.assertEqual(actual, self.u_prefix + expected)
         self.assertEqual(ast.literal_eval(actual), s)
Exemple #23
0
 def test_unicode_examples_multiline(self):
     for u, _, expected in self.unicode_examples:
         actual = text_repr(u, multiline=True)
         self.assertEqual(actual, self.u_prefix + expected)
         self.assertEqual(eval(actual), u)
Exemple #24
0
 def test_bytes_examples_multiline(self):
     for b, _, expected in self.bytes_examples:
         actual = text_repr(b, multiline=True)
         self.assertEqual(actual, self.b_prefix + expected)
         self.assertEqual(eval(actual), b)
Exemple #25
0
 def test_bytes_examples_oneline(self):
     for b, expected, _ in self.bytes_examples:
         actual = text_repr(b, multiline=False)
         self.assertEqual(actual, self.b_prefix + expected)
         self.assertEqual(eval(actual), b)
Exemple #26
0
 def test_ascii_examples_defaultline_unicode(self):
     for s, one, multi in self.ascii_examples:
         expected = "\n" in s and multi or one
         self.assertEqual(text_repr(_u(s)), self.u_prefix + expected)
Exemple #27
0
 def test_ascii_examples_multiline_unicode(self):
     for s, _, expected in self.ascii_examples:
         u = _u(s)
         actual = text_repr(u, multiline=True)
         self.assertEqual(actual, self.u_prefix + expected)
         self.assertEqual(eval(actual), u)
Exemple #28
0
 def test_ascii_examples_multiline_bytes(self):
     for s, _, expected in self.ascii_examples:
         b = _b(s)
         actual = text_repr(b, multiline=True)
         self.assertEqual(actual, self.b_prefix + expected)
         self.assertEqual(eval(actual), b)
Exemple #29
0
 def test_unicode_examples_oneline(self):
     for u, expected, _ in self.unicode_examples:
         actual = text_repr(u, multiline=False)
         self.assertEqual(actual, self.u_prefix + expected)
         self.assertEqual(ast.literal_eval(actual), u)
Exemple #30
0
 def describe(self):
     return "%s does not end with %s." % (
         text_repr(self.matchee), text_repr(self.expected))
Exemple #31
0
 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)