-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
126 lines (91 loc) · 3.33 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from puzzle import Puzzle, Plugin
from os.path import isfile, join, getsize
from os import getcwd
import unittest
from puzzle.core.state import statemachine
PATH = "plugins"
class PuzzleTestBasic(unittest.TestCase):
def setUp(self):
self.p = Puzzle(plugins_dir=join(getcwd(), PATH))
def test_creation_puzzle(self):
self.assertIsNotNone("Creating instance of Puzzle.", self.p)
def test_table_load(self):
self.assertIsNotNone("Creating instance of Puzzle.", self.p.table)
def test_observer_load(self):
self.assertIsNotNone("Creating instance of Puzzle.", self.p.observable)
def test_loading_plugins(self):
self.p.load_plugins()
self.assertEqual(self.p.table.size(), 2)
def test_plugins_instalation(self):
for id,(key, plugin) in enumerate(self.p.table_items()):
self.assertTrue(issubclass(plugin, Plugin))
class PuzzleTestLifecycle(unittest.TestCase):
def setUp(self):
self.p = Puzzle(plugins_dir=join(getcwd(), PATH))
def test_creation_puzzle(self):
self.assertIsNotNone("Creating instance of Puzzle.", self.p)
def test_loading_plugins(self):
self.p.load_plugins()
self.assertEqual(self.p.table.size(), 2)
def test_resolve_state(self):
self.p.load_plugins()
self.p.table.resolve_all()
for key, plugin in self.p.table_items():
self.assertIsInstance(plugin.state, statemachine.Resolved)
def test_active_state(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
for key, plugin in self.p.table_items():
self.assertIsInstance(plugin.state, statemachine.Active)
def test_stop_plugin(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
self.p.table.stop_plugin(0)
plugin = self.p.table.get_plugin(0)
self.assertIsInstance(plugin.state, statemachine.Stopped)
def test_restart_plugin(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
self.p.table.stop_plugin(0)
self.p.table.restart_plugin(0)
plugin = self.p.table.get_plugin(0)
self.assertIsInstance(plugin.state, statemachine.Resolved)
def test_unregister_no_plugin_refresh(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
self.p.table.stop_plugin(0)
self.p.table.unregister_plugin(0, False)
self.assertEqual(self.p.table.size(), 1)
def test_unregister_plugin_refresh(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
self.p.table.stop_plugin(0)
self.p.table.unregister_plugin(0, True)
self.assertEqual(self.p.table.size(), 2)
def test_resolve_plugin_after_refresh(self):
self.p.load_plugins()
self.p.table.resolve_all()
self.p.table.activate_all()
self.p.table.stop_plugin(0)
self.p.table.unregister_plugin(0, True)
self.p.table.resolve(0)
plugin = self.p.table.get_plugin(0)
self.assertIsInstance(plugin.state, statemachine.Resolved)
class PuzzleTestDownloadPluginArchive(unittest.TestCase):
def setUp(self):
self.p = Puzzle(plugins_dir=join(getcwd(), PATH))
def test_download_archive(self):
self.p.load_plugins()
url = 'file:///path_to_test_plugin_archive.zip'
self.p.download_puzzle_part(url)
self.assertEqual(self.p.table.size(), 3)
def test_plugins_instalation(self):
for id,(key, plugin) in enumerate(self.p.table_items()):
self.assertTrue(issubclass(plugin, Plugin))
if __name__ == '__main__':
unittest.main()