-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexamples.py
More file actions
73 lines (52 loc) · 1.71 KB
/
examples.py
File metadata and controls
73 lines (52 loc) · 1.71 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import collections
if os.environ.get("HAMCREST"):
from hamcrest import *
else:
from precisely.hamcrest import *
User = collections.namedtuple("User", ["username", "email_address"])
def test_anything():
assert_that(1, anything())
def test_equal_to():
assert_that(1, equal_to(2))
def test_has_property_wrong_value():
assert_that(User("bob", None), has_property("username", "bobbity"))
def test_has_property_missing():
assert_that("bob", has_property("username", "bobbity"))
def test_has_properties_wrong_value():
assert_that(User("bob", "bob@example.com"), has_properties(
username="bob",
email_address="bobbity@example.com",
))
def test_all_of():
assert_that(User("bob", "bob@example.com"), all_of(
has_property("username", "bob"),
has_property("email_address", "bobbity@example.com"),
))
def test_contains_inanyorder_missing_elements():
assert_that(
[
User("bob", "jim@example.com"),
User("jim", "bob@example.com"),
],
contains_inanyorder(
has_properties(username="bob", email_address="bob@example.com"),
has_properties(username="jim", email_address="jim@example.com"),
)
)
def test_contains_inanyorder_extra_elements():
assert_that(
["apple", "banana"],
contains_inanyorder("apple"),
)
def test_contains_missing_elements():
assert_that(
[
User("bob", "jim@example.com"),
User("jim", "bob@example.com"),
],
contains(
has_properties(username="bob", email_address="bob@example.com"),
has_properties(username="jim", email_address="jim@example.com"),
)
)