-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmt_str.py
62 lines (42 loc) · 1.45 KB
/
tmt_str.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
import unittest
from teach_me_doctests import to_upper
class TestX(unittest.TestCase):
def test_to_upper(self):
self.assertEqual(to_upper("foo"),"FOO")
def test_to_upper_locals(self):
expected = "FOO"
actual = to_upper("foo")
self.assertEqual(actual, expected)
actual = to_upper("FOO")
self.assertEqual(actual, expected)
actual = to_upper("FoO")
self.assertEqual(actual, expected)
def test_almost_eq(self):
self.assertAlmostEqual(2.0,1.9999999,5)
def test_d_eq(self):
a = {"key":"val"}
b = a
self.assertDictEqual(a,b)
#def test_raise(self):
# a = 10/0
# self.assertRaises('ZeroDivisionError')
def test_raise_in(self):
# Less strict matching to facilitate custom err msg
try:
a = 10/0
except Exception as e:
self.assertIn('ZeroDivision', str(type(e)))
#def test_exception_is_raised(self):
# with self.assertRaises(ZeroDivisionError) as e:
# # division_raises()
# a = 10/0
# self.assertEqual('Foo Exception occurred', e.exception.message)
def test_d_eq(self):
a = {"a":1,"b":2}
b = {"a":1}
self.assertDictContainsSubset(b,a)
class TestY(unittest.TestCase):
def test_to_upper(self):
self.assertEqual(to_upper("foo"),"FOO")
if __name__ == "__main__":
unittest.main()