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):
41
41
]
42
42
43
43
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
+
44
65
class _Anything :
45
66
def __eq__ (self , target : object ) -> bool :
46
67
"""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:
18
18
_HelloTuple = namedtuple ("_HelloTuple" , ["hello" ])
19
19
20
20
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
+
21
34
def test_any_matcher () -> None :
22
35
"""It should have an "anything except None" matcher."""
23
36
assert 1 == matchers .Anything ()
@@ -26,6 +39,7 @@ def test_any_matcher() -> None:
26
39
assert [] == matchers .Anything ()
27
40
assert ("hello" , "world" ) == matchers .Anything ()
28
41
assert SomeClass () == matchers .Anything ()
42
+ assert None != matchers .Anything () # noqa: E711
29
43
30
44
31
45
def test_is_a_matcher () -> None :
You can’t perform that action at this time.
0 commit comments