-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathany_of_tests.py
More file actions
44 lines (28 loc) · 1.19 KB
/
any_of_tests.py
File metadata and controls
44 lines (28 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import collections
from precisely import any_of, has_attr, equal_to
from precisely.results import matched, unmatched
User = collections.namedtuple("User", ["username", "email_address"])
def test_matches_when_submatchers_all_match():
matcher = any_of(
has_attr("username", equal_to("bob")),
has_attr("email_address", equal_to("bob@example.com")),
)
assert matched() == matcher.match(User("bob", "bob@example.com"))
def test_matches_when_any_submatchers_match():
matcher = any_of(
equal_to("bob"),
equal_to("jim"),
)
assert matched() == matcher.match("bob")
def test_mismatches_when_no_submatchers_match():
matcher = any_of(
equal_to("bob"),
equal_to("jim"),
)
assert unmatched("did not match any of:\n * 'bob' [was 'alice']\n * 'jim' [was 'alice']") == matcher.match("alice")
def test_description_contains_descriptions_of_submatchers():
matcher = any_of(
has_attr("username", equal_to("bob")),
has_attr("email_address", equal_to("bob@example.com")),
)
assert "any of:\n * object with attribute username: 'bob'\n * object with attribute email_address: 'bob@example.com'" == matcher.describe()