summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Connors <benconnors@outlook.com>2019-09-26 21:42:14 -0400
committerBen Connors <benconnors@outlook.com>2019-09-26 21:42:14 -0400
commitdfe20c0430c7d58b57c44026102cf8b3c52ac1b3 (patch)
tree1c0ad08b16c0183b4bb3c7ebff358950e3971534 /tests
parentcefc580a2f38f14c0245c9d6a5acbaa67feaf8d4 (diff)
Lots of stuff
- Add tests for chaser steps - Finish preliminary implementation of chasers - Implement (de)serialization on chasers and steps - Various bugfixes from testing
Diffstat (limited to 'tests')
-rw-r--r--tests/test_functions_chaserstep.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/test_functions_chaserstep.py b/tests/test_functions_chaserstep.py
new file mode 100644
index 0000000..134b893
--- /dev/null
+++ b/tests/test_functions_chaserstep.py
@@ -0,0 +1,124 @@
+import datetime as dt
+
+import pytest
+
+from blc2.functions.chaserstep import ChaserStep
+from blc2.topology import Fixture
+from blc2.functions.scene import Scene
+from blc2.functions.audio import Audio
+from blc2.workspace import Workspace
+from blc2.constants import INHERIT, MANUAL, EXTERNAL, INTERNAL, INFTY
+
+class DummyChaser:
+ def register_step(self, *args, **kwargs):
+ return
+
+ def __init__(self, w):
+ self.w = w
+
+@pytest.fixture
+def cw():
+ w = Workspace("", "", "", dt.datetime.now())
+ f = Fixture(w=w, id_=0, channel_count=1)
+ c0, = f.channels
+ f2 = Fixture(w=w, id_=1, channel_count=4)
+ Scene(w=w, id_=0, values={c0: 255})
+ Scene(w=w, id_=1, values={c: 255-i for i, c in enumerate(f2.channels)})
+ Audio(w=w, id_=2, filename="tests/silence.m4a")
+
+ return w
+
+def test_chaserstep(cw):
+ c = DummyChaser(cw)
+ s0 = cw.functions[0]
+ s1 = cw.functions[1]
+ a = cw.functions[2]
+ c0, = cw.fixtures[0].channels
+
+ ## Test how it handles inherit
+ cs1 = ChaserStep(c, function=s0, duration_mode=INHERIT)
+ assert cs1.duration == INFTY
+ assert cs1.actual_duration == INFTY
+ assert cs1.fade_out_mode == s0.fade_out_mode
+ assert cs1.scope == s0.scope
+ assert cs1.audio_scope == s0.audio_scope
+
+ cs1.fade_in = 1000
+ cs1.fade_out = 1000
+ assert cs1.duration == INFTY
+ assert cs1.actual_duration == INFTY
+
+ data = cs1._get_data(0, 0)
+ lc, ac, data = cs1.render(500, data)
+ assert not ac
+ assert lc == ((c0, 127),)
+
+ lc, ac, data = cs1.render(1000, data)
+ assert not ac
+ assert lc == ((c0, 255),)
+
+ data.end_time = 1500
+ lc, ac, data = cs1.render(2000, data)
+ assert not ac
+ assert lc == ((c0, 127),)
+
+ lc, ac, data = cs1.render(2501, data)
+ assert not ac
+ assert not lc
+
+ ## Test how it handles manual mode
+ cs1.duration_mode = MANUAL
+ cs1.duration = 1500
+ assert cs1.duration == 1500
+ assert cs1.actual_duration == 2500
+
+ data = cs1._get_data(0, 0)
+ lc, ac, data = cs1.render(500, data)
+ assert not ac
+ assert lc == ((c0, 127),)
+
+ lc, ac, data = cs1.render(1000, data)
+ assert not ac
+ assert lc == ((c0, 255),)
+
+ lc, ac, data = cs1.render(2000, data)
+ assert not ac
+ assert lc == ((c0, 127),)
+
+ lc, ac, data = cs1.render(2501, data)
+ assert not ac
+ assert not lc
+
+ ## Test how it handles inherit and a function change
+ cs1.duration_mode = INHERIT
+ assert cs1.duration == INFTY
+ assert cs1.actual_duration == INFTY
+
+ data = cs1._get_data(0, 0)
+
+ cs1.fade_out = 0
+ cs1.fade_in = 0
+ cs1.function = a
+ if a.actual_duration != 3024:
+ raise ValueError("silence.m4a is wrong duration, fix the tests")
+ assert cs1.audio_scope == a.audio_scope
+ assert cs1.scope == a.scope
+ assert cs1.duration == a.actual_duration
+ assert cs1.actual_duration == a.actual_duration
+ cs1.fade_out = 1000
+ cs1.fade_in = 1000
+ assert cs1.duration == a.actual_duration-1000
+
+ lc, ac, data = cs1.render(500, data)
+ assert not lc
+ assert len(ac) == 1
+ assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 2024, 1000)
+ a.fade_out = 2000
+ lc, ac, data = cs1.render(501, data)
+ assert not lc
+ assert len(ac) == 1
+ assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 1024, 2000)
+
+ lc, ac, data = cs1.render(3025, data)
+ assert not lc
+ assert not ac