| blc2 - Python library and frontend for running theatrical lighting and SFX. Written for the English 2041F fall 2019 theatre production of "The Cenci".
git clone https://benconnors.ca/git-repos/blc2 |
test_functions_scene.py (4204B) - raw
1 """Tests for scene primitive.""" 2 3 import xml.etree.ElementTree as et 4 5 import pytest 6 7 from blc2.functions.scene import Scene 8 from blc2.constants import INFTY, BXW 9 from blc2.exceptions import LoadError 10 11 def test_scene(aws): 12 """Test creation and modification of scenes.""" 13 c1, c2, c3, c4 = aws.fixtures[0].channels 14 15 s1 = Scene(aws) 16 assert s1.scope == frozenset() 17 assert s1.scope == frozenset() 18 19 values = {c1: 0, c2: 1, c3: 2, c4: 4} 20 s1.values = values 21 assert s1.values == values 22 assert s1.scope == frozenset(values.keys()) 23 24 s1.update({c1: 10}) 25 assert s1.values[c1] == 10 26 assert s1.scope == frozenset(values.keys()) 27 for c, v in values.items(): 28 if c == c1: 29 continue 30 assert v == s1.values[c] 31 32 s1.set(values) 33 assert s1.values == values 34 assert s1.scope == frozenset(values.keys()) 35 36 del s1[c1] 37 assert s1.scope == {c2, c3, c4} 38 assert c1 not in s1.values 39 assert s1[c1] is None 40 41 s1[c1] = 10 42 assert s1.scope == frozenset(values.keys()) 43 assert s1[c1] == 10 44 45 assert s1.duration == INFTY 46 assert s1.actual_duration == INFTY 47 assert s1.fade_in == 0 48 assert s1.fade_out == 0 49 assert not s1.audio_scope 50 51 with pytest.raises(Exception): 52 s1.duration = 0 53 54 with pytest.raises(Exception): 55 s1.actual_duration = 0 56 57 with pytest.raises(Exception): 58 s1.fade_in = 0 59 60 with pytest.raises(Exception): 61 s1.fade_out = 0 62 63 with pytest.raises(Exception): 64 s1.scope = frozenset() 65 66 with pytest.raises(Exception): 67 s1.audio_scope = frozenset() 68 69 s1.set(values) 70 lc, ac, _ = s1.render(0) 71 assert ac == () 72 assert dict(lc) == values 73 74 lc, ac, _ = s1.render(1234567890) 75 assert ac == () 76 assert dict(lc) == values 77 78 s1[c1] = 10 79 lc, ac, _ = s1.render(1) 80 assert dict(lc)[c1] == 10 81 assert False not in (v == values[c] for c, v in lc if c != c1) 82 83 with pytest.raises(ValueError): 84 s1[c1] = -10 85 assert s1[c1] == 10 86 87 with pytest.raises(ValueError): 88 s1[c1] = -256 89 assert s1[c1] == 10 90 91 assert s1.copy_data(None) is None 92 93 del s1[c4] 94 del s1[c4] 95 96 def test_scene_serialize(aws, test_xml_eq): 97 c1, c2, c3, c4 = aws.fixtures[0].channels 98 s = Scene(aws, id_=123, name="Test Scene", values={c1: 1, c2: 2, c3: 3, c4: 4}) 99 100 (f1, i1), (f2, i2), (f3, i3), (f4, i4) = ((i.f.id, i.id) for i in (c1, c2, c3, c4)) 101 102 e = s.serialize() 103 expected = """ 104 <function xmlns="{bxw}" type="Scene" id="123" name="Test Scene"> 105 <value fixture="{f1}" channel="{i1}">1</value> 106 <value fixture="{f2}" channel="{i2}">2</value> 107 <value fixture="{f3}" channel="{i3}">3</value> 108 <value fixture="{f4}" channel="{i4}">4</value> 109 </function> 110 """.format(bxw=BXW.strip("{}"), f1=f1, f2=f2, f3=f3, f4=f4, i1=i1,i2=i2,i3=i3,i4=i4).replace("\n", "") 111 112 et.register_namespace("", BXW) 113 114 assert test_xml_eq(e, expected) 115 116 def test_scene_deserialize(aws, test_xml_eq): 117 fail = [ 118 """<function xmlns={} type="asdf"/>""", 119 """<asdf/>""", 120 """<function xmlns={} type="Scene" id="asdf"/>""", 121 """<function xmlns={} type="Scene" id="123" name="Test Scene"> 122 <asdf/></function>""", 123 """<function xmlns={} type="Scene" id="123" name="Test Scene"> 124 <value/></function>""", 125 """<function xmlns={} type="Scene" id="123" name="Test Scene"> 126 <value fixture="10" channel="45"/></function>""", 127 """<function xmlns={} type="Scene" id="123" name="Test Scene"> 128 <value fixture="0" channel="10"/></function>""", 129 """<function xmlns={} type="Scene" id="123" name="Test Scene"> 130 <value fixture="0" channel="1"/></function>""", 131 ] 132 133 for case in fail: 134 case = case.format('"'+BXW.strip("{}")+'"') 135 with pytest.raises(LoadError): 136 Scene.deserialize(aws, et.fromstring(case)) 137 138 139 case = """<function xmlns={} type="Scene" id="123" name="Test Scene"> 140 <value fixture="0" channel="0">123</value></function>""" 141 case = case.format('"'+BXW.strip("{}")+'"').replace('\n', "") 142 143 s = Scene.deserialize(aws, et.fromstring(case)) 144 145 assert test_xml_eq(s.serialize(), case)