Ejemplo n.º 1
0
 def test_if_message_given_message(self):
     # Annotate.if_message returns an annotated version of the matcher if a
     # message is provided.
     matcher = Equals(1)
     expected = Annotate("foo", matcher)
     annotated = Annotate.if_message("foo", matcher)
     self.assertThat(annotated, MatchesStructure.fromExample(expected, "annotation", "matcher"))
Ejemplo n.º 2
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 self.failureException: 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():
            full_name = name
            suffix = 1
            while full_name in existing_details:
                full_name = "%s-%d" % (name, suffix)
                suffix += 1
            self.addDetail(full_name, content)
        if verbose:
            message = (
                'Match failed. Matchee: "%s"\nMatcher: %s\nDifference: %s\n'
                % (matchee, matcher, mismatch.describe()))
        else:
            message = mismatch.describe()
        self.fail(message)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def test_if_message_given_message(self):
     # Annotate.if_message returns an annotated version of the matcher if a
     # message is provided.
     matcher = Equals(1)
     expected = Annotate('foo', matcher)
     annotated = Annotate.if_message('foo', matcher)
     self.assertThat(
         annotated,
         MatchesStructure.fromExample(expected, 'annotation', 'matcher'))
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
    def _expectThat(self, matchee, matcher, message='', verbose=False):

        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():
            full_name = name
            suffix = 1
            while full_name in existing_details:
                full_name = "%s-%d" % (name, suffix)
                suffix += 1
                self.addDetail(full_name, content)

        raise MismatchError(matchee, matcher, mismatch, verbose)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def _expectThat(self, matchee, matcher, message='', verbose=False):

        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():
            full_name = name
            suffix = 1
            while full_name in existing_details:
                full_name = "%s-%d" % (name, suffix)
                suffix += 1
                self.addDetail(full_name, content)

        raise MismatchError(matchee, matcher, mismatch, verbose)
Ejemplo n.º 12
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():
            full_name = name
            suffix = 1
            while full_name in existing_details:
                full_name = "%s-%d" % (name, suffix)
                suffix += 1
            self.addDetail(full_name, content)
        raise MismatchError(matchee, matcher, mismatch, verbose)
Ejemplo n.º 13
0
 def test_if_message_no_message(self):
     # Annotate.if_message returns the given matcher if there is no
     # message.
     matcher = Equals(1)
     not_annotated = Annotate.if_message('', matcher)
     self.assertIs(matcher, not_annotated)
Ejemplo n.º 14
0
 def test_if_message_no_message(self):
     # Annotate.if_message returns the given matcher if there is no
     # message.
     matcher = Equals(1)
     not_annotated = Annotate.if_message('', matcher)
     self.assertIs(matcher, not_annotated)