-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
56 lines (41 loc) · 1.55 KB
/
tests.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
import unittest
from regis import PermissionError, Registry, RegistryMixin
class TestRegistry(unittest.TestCase):
def test_register_class(self):
registry = Registry()
class ExampleClass(RegistryMixin):
pass
example_instance = ExampleClass()
example_instance.register()
self.assertIn(ExampleClass, registry._registered_classes)
def test_unregister_class(self):
registry = Registry()
class ExampleClass(RegistryMixin):
pass
example_instance = ExampleClass()
example_instance.register()
example_instance.unregister()
self.assertNotIn(ExampleClass, registry._registered_classes)
def test_set_item(self):
registry = Registry()
class ExampleClass(RegistryMixin):
pass
example_instance = ExampleClass()
example_instance.register()
example_instance.set_item('key', 'value')
self.assertEqual(registry._items['key'], 'value')
def test_get_item(self):
class ExampleClass(RegistryMixin):
pass
example_instance = ExampleClass()
example_instance.register()
example_instance.set_item('key', 'value')
self.assertEqual(example_instance.get_item('key'), 'value')
def test_permission_error(self):
class ExampleClass(RegistryMixin):
pass
example_instance = ExampleClass()
with self.assertRaises(PermissionError):
example_instance.set_item('key', 'value')
if __name__ == '__main__':
unittest.main()