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
|
from chrysacase import ChrysalideTestCase
from pychrysalide.plugins import PluginModule
class TestPlugin(ChrysalideTestCase):
"""TestCase for GPluginModule."""
def testPluginInfoImplementations(self):
"""Retrieve plugin basic information provided by __init__()."""
class MyPlugin(PluginModule):
def __init__(self):
super().__init__('custom-name', desc='custom-desc', url='custom-url', version='0.0.1')
my = MyPlugin()
self.assertEqual(my.name, 'custom-name')
self.assertEqual(my.desc, 'custom-desc')
self.assertEqual(my.version, '0.0.1')
self.assertEqual(my.url, 'custom-url')
def testPluginMethodImplementations(self):
"""Ensure required plugins abstract methods can be implemented."""
class MyWrongPlugin(PluginModule):
def __init__(self):
super().__init__('pg-name')
my = MyWrongPlugin()
with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_filename'"):
print(my.filename)
with self.assertRaisesRegex(NotImplementedError, "method implementation is missing for '_get_modname'"):
print(my.modname)
class MyPlugin(PluginModule):
def __init__(self):
super().__init__('pg-name')
def _get_filename(self):
return 'file-name'
def _get_modname(self):
return 'mod-name'
my = MyPlugin()
self.assertEqual(my.filename, 'file-name')
self.assertEqual(my.modname, 'mod-name')
def testPluginRequirementIncludePython(self):
"""Ensure that plugin requirements include the Python bindings."""
class MyPlugin(PluginModule):
def __init__(self):
super().__init__('pg-name')
my = MyPlugin()
self.assertEqual(len(my.requirements), 1)
self.assertEqual(my.requirements[0], 'PyChrysalide')
def testPluginRequirementUniqueness(self):
"""Ensure that plugin requirements are unique."""
class MyPlugin(PluginModule):
def __init__(self):
super().__init__('pg-name', required=[ 'PyChrysalide' ])
my = MyPlugin()
self.assertEqual(my.requirements.count('PyChrysalide'), 1)
class MyPlugin2(PluginModule):
def __init__(self):
super().__init__('pg-name2', required=[ 'AA', 'BB', 'AA' ])
my = MyPlugin2()
self.assertEqual(my.requirements.count('AA'), 1)
self.assertEqual(my.requirements.count('PyChrysalide'), 1)
|