forked from cloud-custodian/cloud-custodian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_registry.py
69 lines (47 loc) · 1.71 KB
/
test_registry.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
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
import unittest
from c7n.registry import PluginRegistry
class RegistryTest(unittest.TestCase):
def test_unregister(self):
registry = PluginRegistry('dummy')
klass = lambda: 1 # NOQA
registry.register('dust', klass)
self.assertEqual(list(registry.keys()), ['dust'])
self.assertEqual(list(registry.values()), [klass])
registry.unregister('dust')
def test_registry_getitem_keyerror(self):
registry = PluginRegistry('dummy')
try:
registry['xyz']
except KeyError:
pass
else:
self.fail('should have raised keyerror')
def test_event_subscriber(self):
observed = []
def observer(*args):
observed.append(args)
registry = PluginRegistry('dummy')
@registry.register('hot')
class _plugin_impl1:
pass
registry.subscribe(observer)
@registry.register('water')
class _plugin_impl2:
pass
self.assertEqual(observed, [])
registry.notify(_plugin_impl1)
registry.notify(_plugin_impl2)
self.assertEqual(observed[1], (registry, _plugin_impl2))
self.assertEqual(list(sorted(registry.keys())), ['hot', 'water'])
def test_condition(self):
registry = PluginRegistry('dummy')
@registry.register('mud', condition=False)
class _plugin_impl:
pass
self.assertEqual(list(registry.keys()), [])
def _plugin_impl_func():
pass
registry.register('concrete', _plugin_impl_func, condition=False)
self.assertEqual(list(registry.keys()), [])