-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_datadiff_tools.py
83 lines (70 loc) · 2.09 KB
/
test_datadiff_tools.py
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
74
75
76
77
78
79
80
81
82
83
import sys
from textwrap import dedent
from datadiff import tools
from test_datadiff import assert_equal
def test_assert_equal_true():
# nothing raised
assert_equal(None, tools.assert_equals(7, 7))
def test_assert_equal_false():
try:
tools.assert_equals([3,4], [5,6])
except:
e = sys.exc_info()[1]
assert_equal(type(e), AssertionError)
assert_equal(str(e), dedent('''\
--- a
+++ b
[
@@ -0,1 +0,1 @@
-3,
-4,
+5,
+6,
]'''))
else:
raise AssertionError("Should've raised an AssertionError")
def test_assert_equal_msg():
try:
tools.assert_equals(3, 4, "whoops")
except:
e = sys.exc_info()[1]
assert_equal(type(e), AssertionError,
"Raised exception should be AssertionError")
assert_equal(str(e), "whoops")
else:
raise AssertionError("Should've raised an AssertionError")
def test_assert_equals():
assert_equal(tools.assert_equal, tools.assert_equals)
def test_assert_equal_simple():
try:
tools.assert_equals(True, False)
except:
e = sys.exc_info()[1]
assert_equal(type(e), AssertionError)
assert_equal(str(e), dedent('''\
True != False'''))
else:
raise AssertionError("Should've raised an AssertionError")
def test_assert_equal_simple_types():
try:
tools.assert_equals('a', 7)
except:
e = sys.exc_info()[1]
assert_equal(type(e), AssertionError)
assert_equal(str(e), dedent('''\
'a' != 7'''))
else:
raise AssertionError("Should've raised an AssertionError")
if __name__ == '__main__':
try:
import nose
except (ImportError, SyntaxError, NameError):
pass
else:
nose.main()
sys.exit(0)
import types
for fn_name, fn in sorted(locals().items()):
if fn_name.startswith('test_') and type(fn) == types.FunctionType:
sys.stderr.write(fn_name + '...\n')
fn()