Skip to content

Commit 0ef413a

Browse files
committed
Add testtools.matchers.test module
End users can provide their own matchers. It is helpful to provide a test harness for them to use to test this. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 6953ff2 commit 0ef413a

File tree

10 files changed

+13
-66
lines changed

10 files changed

+13
-66
lines changed

tests/matchers/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
_BinaryMismatch,
2525
_NotNearlyEqual,
2626
)
27+
from testtools.matchers.test import TestMatchersInterface
2728

2829
from ..helpers import FullStackRunTest
29-
from ..matchers.helpers import TestMatchersInterface
3030

3131

3232
class Test_BinaryMismatch(TestCase):

tests/matchers/test_const.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from testtools import TestCase
66
from testtools.matchers import Always, Never
7-
8-
from ..matchers.helpers import TestMatchersInterface
7+
from testtools.matchers.test import TestMatchersInterface
98

109

1110
class TestAlwaysInterface(TestMatchersInterface, TestCase):

tests/matchers/test_datastructures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
MatchesSetwise,
2121
MatchesStructure,
2222
)
23+
from testtools.matchers.test import TestMatchersInterface
2324

2425
from ..helpers import FullStackRunTest
25-
from ..matchers.helpers import TestMatchersInterface
2626

2727

2828
def run_doctest(obj, name):

tests/matchers/test_dict.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
MatchesDict,
1515
_SubDictOf,
1616
)
17-
18-
from ..matchers.helpers import TestMatchersInterface
17+
from testtools.matchers.test import TestMatchersInterface
1918

2019

2120
class TestMatchesAllDictInterface(TestCase, TestMatchersInterface):

tests/matchers/test_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from testtools import TestCase
77
from testtools.matchers._doctest import DocTestMatches
8+
from testtools.matchers.test import TestMatchersInterface
89

910
from ..helpers import FullStackRunTest
10-
from ..matchers.helpers import TestMatchersInterface
1111

1212

1313
class TestDocTestMatchesInterface(TestCase, TestMatchersInterface):

tests/matchers/test_exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
Raises,
1414
raises,
1515
)
16+
from testtools.matchers.test import TestMatchersInterface
1617

1718
from ..helpers import FullStackRunTest
18-
from ..matchers.helpers import TestMatchersInterface
1919

2020

2121
def make_error(type, *args, **kwargs):

tests/matchers/test_higherorder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
MatchesPredicateWithParams,
2424
Not,
2525
)
26+
from testtools.matchers.test import TestMatchersInterface
2627

2728
from ..helpers import FullStackRunTest
28-
from ..matchers.helpers import TestMatchersInterface
2929

3030

3131
class TestAllMatch(TestCase, TestMatchersInterface):

tests/matchers/test_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
MatchesStructure,
1414
)
1515
from testtools.matchers._warnings import IsDeprecated, WarningMessage, Warnings
16+
from testtools.matchers.test import TestMatchersInterface
1617

1718
from ..helpers import FullStackRunTest
18-
from ..matchers.helpers import TestMatchersInterface
1919

2020

2121
def make_warning(warning_type, message):
Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,15 @@
11
# Copyright (c) 2008-2012 testtools developers. See LICENSE for details.
22

33
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
66

77
warnings.warn(
88
"This module is deprecated for removal",
99
DeprecationWarning,
1010
stacklevel=2,
1111
)
1212

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

Comments
 (0)