File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,27 @@ def test_logger_called(decoy: Decoy):
4141]
4242
4343
44+ class _AnythingOrNone :
45+ def __eq__ (self , target : object ) -> bool :
46+ return True
47+
48+ def __repr__ (self ) -> str :
49+ """Return a string representation of the matcher."""
50+ return "<AnythingOrNone>"
51+
52+
53+ def AnythingOrNone () -> Any :
54+ """Match anything including None.
55+
56+ !!! example
57+ ```python
58+ assert "foobar" == AnythingOrNone()
59+ assert None == AnythingOrNone()
60+ ```
61+ """
62+ return _AnythingOrNone ()
63+
64+
4465class _Anything :
4566 def __eq__ (self , target : object ) -> bool :
4667 """Return true if target is not None."""
Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ def goodbye(self) -> str:
1818_HelloTuple = namedtuple ("_HelloTuple" , ["hello" ])
1919
2020
21+ def test_anything_or_none_matcher () -> None :
22+ """It should have an "anything including None" matcher."""
23+ assert 1 == matchers .AnythingOrNone ()
24+ assert False == matchers .AnythingOrNone () # noqa: E712
25+ assert {} == matchers .AnythingOrNone ()
26+ assert [] == matchers .AnythingOrNone ()
27+ assert ("hello" , "world" ) == matchers .AnythingOrNone ()
28+ assert SomeClass () == matchers .AnythingOrNone ()
29+ assert None == matchers .AnythingOrNone () # noqa: E711
30+
31+ assert str (matchers .AnythingOrNone ()) == "<AnythingOrNone>"
32+
33+
2134def test_any_matcher () -> None :
2235 """It should have an "anything except None" matcher."""
2336 assert 1 == matchers .Anything ()
@@ -26,6 +39,7 @@ def test_any_matcher() -> None:
2639 assert [] == matchers .Anything ()
2740 assert ("hello" , "world" ) == matchers .Anything ()
2841 assert SomeClass () == matchers .Anything ()
42+ assert None != matchers .Anything () # noqa: E711
2943
3044
3145def test_is_a_matcher () -> None :
You can’t perform that action at this time.
0 commit comments