Exemplo n.º 1
0
 def _matchHelper(self, matchee, matcher, message, verbose):
     matcher = Annotate.if_message(message, matcher)
     mismatch = matcher.match(matchee)
     if not mismatch:
         return
     for (name, value) in mismatch.get_details().items():
         self.addDetailUniqueName(name, value)
     return MismatchError(matchee, matcher, mismatch, verbose)
Exemplo n.º 2
0
 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))
Exemplo n.º 3
0
    def assertThat(self, matchee, matcher, message='', verbose=False):
        """Assert that matchee is matched by matcher.

        :param matchee: An object to match with matcher.
        :param matcher: An object meeting the testtools.Matcher protocol.
        :raises MismatchError: When matcher does not match thing.
        """
        matcher = Annotate.if_message(message, matcher)
        mismatch = matcher.match(matchee)
        if not mismatch:
            return
        existing_details = self.getDetails()
        for (name, content) in mismatch.get_details().items():
            self.addDetailUniqueName(name, content)
        raise MismatchError(matchee, matcher, mismatch, verbose)
Exemplo n.º 4
0
def assert_that(matchee, matcher, message='', verbose=False):
    """Assert that matchee is matched by matcher.

    This should only be used when you need to use a function based
    matcher, assertThat in Testtools.Testcase is prefered and has more
    features

    :param matchee: An object to match with matcher.
    :param matcher: An object meeting the testtools.Matcher protocol.
    :raises MismatchError: When matcher does not match thing.
    """
    matcher = Annotate.if_message(message, matcher)
    mismatch = matcher.match(matchee)
    if not mismatch:
        return
    raise MismatchError(matchee, matcher, mismatch, verbose)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def test_default_description_is_mismatch(self):
     mismatch = Equals(3).match(2)
     e = MismatchError(2, Equals(3), mismatch)
     self.assertEqual(mismatch.describe(), str(e))
Exemplo n.º 7
0
 def raise_mismatch_error():
     raise MismatchError(2, Equals(3), Equals(3).match(2))
Exemplo n.º 8
0
 def test_default_description_unicode(self):
     matchee = _u('\xa7')
     matcher = Equals(_u('a'))
     mismatch = matcher.match(matchee)
     e = MismatchError(matchee, matcher, mismatch)
     self.assertEqual(mismatch.describe(), str(e))