diff options
Diffstat (limited to 'matchers.py')
-rw-r--r-- | matchers.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/matchers.py b/matchers.py new file mode 100644 index 0000000..e17d651 --- /dev/null +++ b/matchers.py | |||
@@ -0,0 +1,58 @@ | |||
1 | def equal(expected): | ||
2 | def tester(function, *args, **kwargs): | ||
3 | actual = function(*args, **kwargs) | ||
4 | assert actual == expected, "%r != %r" % (actual, expected) | ||
5 | |||
6 | return tester | ||
7 | |||
8 | |||
9 | def be_none(): | ||
10 | def tester(function, *args, **kwargs): | ||
11 | actual = function(*args, **kwargs) | ||
12 | assert actual is None, "%r is not None" % actual | ||
13 | |||
14 | return tester | ||
15 | |||
16 | |||
17 | def be_true(): | ||
18 | def tester(function, *args, **kwargs): | ||
19 | actual = function(*args, **kwargs) | ||
20 | assert actual is True, "%r is not True" % actual | ||
21 | |||
22 | return tester | ||
23 | |||
24 | |||
25 | def be_false(): | ||
26 | def tester(function, *args, **kwargs): | ||
27 | actual = function(*args, **kwargs) | ||
28 | assert actual is False, "%r is not False" % actual | ||
29 | |||
30 | return tester | ||
31 | |||
32 | |||
33 | def be_a(expected): | ||
34 | def tester(function, *args, **kwargs): | ||
35 | actual = function(*args, **kwargs) | ||
36 | assert isinstance(actual, expected), "%r is not a %r" % (actual, expected) | ||
37 | |||
38 | return tester | ||
39 | |||
40 | |||
41 | def be(expected): | ||
42 | def tester(function, *args, **kwargs): | ||
43 | actual = function(*args, **kwargs) | ||
44 | assert actual is expected, "%r is not %r" % (actual, expected) | ||
45 | |||
46 | return tester | ||
47 | |||
48 | |||
49 | def raise_exception(expected): | ||
50 | def tester(function, *args, **kwargs): | ||
51 | try: | ||
52 | function(*args, **kwargs) | ||
53 | except expected: | ||
54 | pass | ||
55 | else: | ||
56 | raise AssertionError("%s not raised" % expected) | ||
57 | |||
58 | return tester | ||