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"))
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)
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)
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)
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'))
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)
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)
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)
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)
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)
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)
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)
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)
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)