testtools: Update to latest version.
[metze/samba/wip.git] / lib / testtools / testtools / tests / matchers / helpers.py
1 # Copyright (c) 2008-2012 testtools developers. See LICENSE for details.
2
3 from testtools.tests.helpers import FullStackRunTest
4
5
6 class TestMatchersInterface(object):
7
8     run_tests_with = FullStackRunTest
9
10     def test_matches_match(self):
11         matcher = self.matches_matcher
12         matches = self.matches_matches
13         mismatches = self.matches_mismatches
14         for candidate in matches:
15             self.assertEqual(None, matcher.match(candidate))
16         for candidate in mismatches:
17             mismatch = matcher.match(candidate)
18             self.assertNotEqual(None, mismatch)
19             self.assertNotEqual(None, getattr(mismatch, 'describe', None))
20
21     def test__str__(self):
22         # [(expected, object to __str__)].
23         from testtools.matchers._doctest import DocTestMatches
24         examples = self.str_examples
25         for expected, matcher in examples:
26             self.assertThat(matcher, DocTestMatches(expected))
27
28     def test_describe_difference(self):
29         # [(expected, matchee, matcher), ...]
30         examples = self.describe_examples
31         for difference, matchee, matcher in examples:
32             mismatch = matcher.match(matchee)
33             self.assertEqual(difference, mismatch.describe())
34
35     def test_mismatch_details(self):
36         # The mismatch object must provide get_details, which must return a
37         # dictionary mapping names to Content objects.
38         examples = self.describe_examples
39         for difference, matchee, matcher in examples:
40             mismatch = matcher.match(matchee)
41             details = mismatch.get_details()
42             self.assertEqual(dict(details), details)