-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_reader.py
142 lines (106 loc) · 4.91 KB
/
test_reader.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import xml.etree.ElementTree as ET
from io import StringIO
from unittest import TestCase
from reader import NS, QLCFile
import snippets
class BasicFileTest(TestCase):
def setUp(self):
super().setUp()
self.virtual_console = snippets.empty_virtual_console
self.simple_desk = snippets.empty_simple_desk
self.fixtures = []
self.functions = []
def get_xml(self):
return '\n'.join((
snippets.header,
snippets.engine_header,
'\n'.join(self.fixtures),
'\n'.join(self.functions),
snippets.engine_footer,
self.virtual_console,
self.simple_desk,
snippets.footer))
class SanityTest(BasicFileTest):
def test_basicfile(self):
x = StringIO(self.get_xml())
r = ET.parse(x).getroot()
# TODO: callout to actual QLC+ to load the file and check it
def test_some_fixtures(self):
self.fixtures = [
snippets.generic_fixture(0, 1),
snippets.generic_fixture(1, 2),
snippets.generic_fixture(2, 3, channels=6),
]
x = StringIO(self.get_xml())
r = ET.parse(x).getroot()
def test_some_functions(self):
self.functions = [
snippets.function_scene(0, "Basic Scene"),
snippets.function_scene(1, "Basic Scene 1"),
snippets.function_scene(2, "Basic Scene 2"),
]
x = StringIO(self.get_xml())
r = ET.parse(x).getroot()
def test_some_fixtures_and_functions(self):
self.fixtures = [
snippets.generic_fixture(0, 1),
snippets.generic_fixture(1, 2),
snippets.generic_fixture(2, 3, channels=6),
]
self.functions = [
snippets.function_scene(0, "Basic Scene"),
snippets.function_scene(1, "Basic Scene 1"),
snippets.function_scene(2, "Basic Scene 2"),
]
x = StringIO(self.get_xml())
r = ET.parse(x).getroot()
# TODO: Functions USING fixtures...
##################################
class TestCopyingSimpleScene(BasicFileTest):
def test_copy_to_blank_file(self):
self.functions = []
empty_file = QLCFile(StringIO(self.get_xml()))
self.functions = [
snippets.function_scene(0, "Basic Scene"),
snippets.function_scene(1, "Basic Scene 1"),
snippets.function_scene(2, "Basic Scene 2"),
]
full_file = QLCFile(StringIO(self.get_xml()))
clipboard = list(full_file.iter_functions_for_clipboard(['0','1','2']))
empty_file.paste_functions_here(clipboard)
new_functions = empty_file.list_functions()
self.assertEqual(new_functions[0].attrib["Name"], "Basic Scene")
self.assertEqual(new_functions[1].attrib["Name"], "Basic Scene 1")
self.assertEqual(new_functions[2].attrib["Name"], "Basic Scene 2")
self.assertEqual(new_functions[0].attrib["ID"], "0")
self.assertEqual(new_functions[1].attrib["ID"], "1")
self.assertEqual(new_functions[2].attrib["ID"], "2")
def test_copy_to_nonempty_file(self):
self.functions = [
snippets.function_scene(0, "Basic Scene"),
snippets.function_scene(1, "Basic Scene 1"),
snippets.function_scene(2, "Basic Scene 2"),
]
to_file = QLCFile(StringIO(self.get_xml()))
self.functions = [
snippets.function_scene(0, "Basic Scene A"),
snippets.function_scene(1, "Basic Scene B"),
snippets.function_scene(2, "Basic Scene C"),
]
from_file = QLCFile(StringIO(self.get_xml()))
clipboard = list(from_file.iter_functions_for_clipboard(['0','1','2']))
to_file.paste_functions_here(clipboard)
new_functions = to_file.list_functions()
self.assertEqual(len(new_functions), 6)
self.assertEqual(new_functions[0].attrib["Name"], "Basic Scene")
self.assertEqual(new_functions[1].attrib["Name"], "Basic Scene 1")
self.assertEqual(new_functions[2].attrib["Name"], "Basic Scene 2")
self.assertEqual(new_functions[3].attrib["Name"], "Basic Scene A")
self.assertEqual(new_functions[4].attrib["Name"], "Basic Scene B")
self.assertEqual(new_functions[5].attrib["Name"], "Basic Scene C")
self.assertEqual(new_functions[0].attrib["ID"], "0")
self.assertEqual(new_functions[1].attrib["ID"], "1")
self.assertEqual(new_functions[2].attrib["ID"], "2")
self.assertEqual(new_functions[3].attrib["ID"], "3")
self.assertEqual(new_functions[4].attrib["ID"], "4")
self.assertEqual(new_functions[5].attrib["ID"], "5")