X-Git-Url: http://git.samba.org/?p=samba.git;a=blobdiff_plain;f=lib%2Fsubunit%2Fpython%2Ftesttools%2Fmatchers.py;h=039c84b7c7e50d7c324ef0131fffbaee554a579d;hp=244daceb7f4bd05c9d5cbb4f7dc04fd51ce88809;hb=082e7f20d7df457c08119eb41fc2f3f8c09ba7ab;hpb=2ec5792a4ba0cefa079a6d7e1b0ec2472151e794 diff --git a/lib/subunit/python/testtools/matchers.py b/lib/subunit/python/testtools/matchers.py index 244daceb7f4..039c84b7c7e 100644 --- a/lib/subunit/python/testtools/matchers.py +++ b/lib/subunit/python/testtools/matchers.py @@ -12,6 +12,7 @@ $ python -c 'import testtools.matchers; print testtools.matchers.__all__' __metaclass__ = type __all__ = [ + 'Annotate', 'DocTestMatches', 'Equals', 'MatchesAll', @@ -249,3 +250,33 @@ class MatchedUnexpectedly: def describe(self): return "%r matches %s" % (self.other, self.matcher) + + +class Annotate: + """Annotates a matcher with a descriptive string. + + Mismatches are then described as ': '. + """ + + def __init__(self, annotation, matcher): + self.annotation = annotation + self.matcher = matcher + + def __str__(self): + return 'Annotate(%r, %s)' % (self.annotation, self.matcher) + + def match(self, other): + mismatch = self.matcher.match(other) + if mismatch is not None: + return AnnotatedMismatch(self.annotation, mismatch) + + +class AnnotatedMismatch: + """A mismatch annotated with a descriptive string.""" + + def __init__(self, annotation, mismatch): + self.annotation = annotation + self.mismatch = mismatch + + def describe(self): + return '%s: %s' % (self.mismatch.describe(), self.annotation)