-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
executable file
·103 lines (69 loc) · 2.11 KB
/
test.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import unittest
from EventManager import EventManager, Event
class TestError(NotImplementedError):
pass
test_event = Event()
def test_func_error():
raise TestError()
def test_func():
pass
def test_func_stop():
raise StopIteration
def test_func_global(name):
raise TestError()
class TestEvents(object):
@staticmethod
def test():
raise TestError()
class EventTest(unittest.TestCase):
def test_creation(self):
Event()
def test_creation_args(self):
e = Event(test_func)
self.assertIn(test_func, e)
def test_clear(self):
e = Event(test_func)
e.clear()
self.assertEqual(len(e), 0)
def test_add_handler(self):
e = Event()
e.add_handler(test_func)
self.assertIn(test_func, e)
def test_add_handler_invalid(self):
e = Event()
with self.assertRaises(TypeError):
e.add_handler("NotCallable")
def test_remove_handler(self):
e = Event()
e.add_handler(test_func)
e.remove_handler(test_func)
self.assertNotIn(test_func, e)
def test_fire(self):
e = Event()
e.add_handler(test_func_error)
with self.assertRaises(TestError):
e()
def test_fire_stop(self):
e = Event()
e.add_handler(test_func_stop)
e.add_handler(test_func_error)
class EventManagerTest(unittest.TestCase):
def test_creation(self):
EventManager()
def test_creation_kwargs(self):
em = EventManager(test=test_event)
self.assertEqual(em.test, test_event)
def test_fire_global(self):
em = EventManager()
em.test = Event(test_func)
em.got_event.add_handler(test_func_global)
with self.assertRaises(TestError):
em.test()
def test_apply(self):
em = EventManager()
events = TestEvents()
em.apply(events)
with self.assertRaises(TestError):
em.test()
if __name__ == "__main__":
unittest.main()