|
1 | 1 | # Copyright (c) 2008-2012 testtools developers. See LICENSE for details. |
2 | 2 |
|
3 | 3 | import warnings |
4 | | -from collections.abc import Callable |
5 | | -from typing import Any, ClassVar, Protocol, runtime_checkable |
| 4 | + |
| 5 | +from testtools.matchers.test import TestMatchersInterface |
6 | 6 |
|
7 | 7 | warnings.warn( |
8 | 8 | "This module is deprecated for removal", |
9 | 9 | DeprecationWarning, |
10 | 10 | stacklevel=2, |
11 | 11 | ) |
12 | 12 |
|
13 | | - |
14 | | -@runtime_checkable |
15 | | -class MatcherTestProtocol(Protocol): |
16 | | - """Protocol for test classes that test matchers.""" |
17 | | - |
18 | | - matches_matcher: ClassVar[Any] |
19 | | - matches_matches: ClassVar[Any] |
20 | | - matches_mismatches: ClassVar[Any] |
21 | | - str_examples: ClassVar[Any] |
22 | | - describe_examples: ClassVar[Any] |
23 | | - assertEqual: Callable[..., Any] |
24 | | - assertNotEqual: Callable[..., Any] |
25 | | - assertThat: Callable[..., Any] |
26 | | - |
27 | | - |
28 | | -class TestMatchersInterface: |
29 | | - """Mixin class that provides test methods for matcher interfaces.""" |
30 | | - |
31 | | - __test__ = False # Tell pytest not to collect this as a test class |
32 | | - |
33 | | - def test_matches_match(self: MatcherTestProtocol) -> None: |
34 | | - matcher = self.matches_matcher |
35 | | - matches = self.matches_matches |
36 | | - mismatches = self.matches_mismatches |
37 | | - for candidate in matches: |
38 | | - self.assertEqual(None, matcher.match(candidate)) |
39 | | - for candidate in mismatches: |
40 | | - mismatch = matcher.match(candidate) |
41 | | - self.assertNotEqual(None, mismatch) |
42 | | - self.assertNotEqual(None, getattr(mismatch, "describe", None)) |
43 | | - |
44 | | - def test__str__(self: MatcherTestProtocol) -> None: |
45 | | - # [(expected, object to __str__)]. |
46 | | - from testtools.matchers._doctest import DocTestMatches |
47 | | - |
48 | | - examples = self.str_examples |
49 | | - for expected, matcher in examples: |
50 | | - self.assertThat(matcher, DocTestMatches(expected)) |
51 | | - |
52 | | - def test_describe_difference(self: MatcherTestProtocol) -> None: |
53 | | - # [(expected, matchee, matcher), ...] |
54 | | - examples = self.describe_examples |
55 | | - for difference, matchee, matcher in examples: |
56 | | - mismatch = matcher.match(matchee) |
57 | | - self.assertEqual(difference, mismatch.describe()) |
58 | | - |
59 | | - def test_mismatch_details(self: MatcherTestProtocol) -> None: |
60 | | - # The mismatch object must provide get_details, which must return a |
61 | | - # dictionary mapping names to Content objects. |
62 | | - examples = self.describe_examples |
63 | | - for difference, matchee, matcher in examples: |
64 | | - mismatch = matcher.match(matchee) |
65 | | - details = mismatch.get_details() |
66 | | - self.assertEqual(dict(details), details) |
| 13 | +__all__ = [ |
| 14 | + "TestMatchersInterface", |
| 15 | +] |
0 commit comments