summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Connors <benconnors@outlook.com>2019-09-27 14:57:46 -0400
committerBen Connors <benconnors@outlook.com>2019-09-27 14:57:46 -0400
commit0fc3371d48d7e87a5628b16c2bbd09c3fb15cd8e (patch)
tree64dd6994f04a08b269dcf14ff5c26b2d2b542db5 /tests
parentdfe20c0430c7d58b57c44026102cf8b3c52ac1b3 (diff)
Bugfixes
- Add some new tests - Run some basic (interactive) chaser tests, they work-ish now
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py15
-rw-r--r--tests/test_constants.py20
-rw-r--r--tests/test_functions_audio.py27
-rw-r--r--tests/test_functions_scene.py38
4 files changed, 98 insertions, 2 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 71bd3ac..1a9af58 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,4 +1,5 @@
import datetime as dt
+import xml.etree.ElementTree as et
import pytest
@@ -16,3 +17,17 @@ def aws():
w = Workspace("", "", "", dt.datetime.now())
Fixture(w, id_=0, channel_count=4)
return w
+
+def elements_equal(e1, e2):
+ if e1.tag != e2.tag: return False
+ if e1.text != e2.text: return False
+ if e1.tail.strip() != e2.tail.strip(): return False
+ if e1.attrib != e2.attrib: return False
+ if len(e1) != len(e2): return False
+ return all(elements_equal(c1, c2) for c1, c2 in zip(e1, e2))
+
+@pytest.fixture
+def test_xml_eq():
+ def inner(e: et.Element, s: str):
+ return elements_equal(e, et.fromstring(s))
+ return inner
diff --git a/tests/test_constants.py b/tests/test_constants.py
new file mode 100644
index 0000000..5ce0b1a
--- /dev/null
+++ b/tests/test_constants.py
@@ -0,0 +1,20 @@
+"""Tests for the constants used.
+
+Mainly just tests the INFTY object.
+"""
+
+import pytest
+
+from blc2.constants import INFTY, _Infinity
+
+def test_infty():
+ assert str(INFTY) == "infty"
+ assert 1+INFTY == INFTY+1 == INFTY
+ assert 1-INFTY == INFTY-1 == INFTY
+ assert 4*INFTY == INFTY*4 == INFTY*0.4 == INFTY
+
+ with pytest.raises(Exception):
+ _ = INFTY * 0
+
+ with pytest.raises(Exception):
+ infty2 = _Infinity()
diff --git a/tests/test_functions_audio.py b/tests/test_functions_audio.py
index de6aa2a..35d548a 100644
--- a/tests/test_functions_audio.py
+++ b/tests/test_functions_audio.py
@@ -1,4 +1,6 @@
-import os
+"""Tests for the audio primitive."""
+
+import pytest
from blc2.functions.audio import Audio
@@ -15,6 +17,7 @@ def test_audio(aws):
assert a.actual_duration == 0
a.filename = "tests/silence.m4a"
+ assert a.filename == "tests/silence.m4a"
assert a.audio_scope == {"tests/silence.m4a"}
assert a.duration == 2024
assert a.actual_duration == 3024
@@ -34,3 +37,25 @@ def test_audio(aws):
_, ac, _ = a.render(5000)
assert not ac
+
+ with pytest.raises(ValueError):
+ _ = Audio(aws, id_=101, fade_in=-10)
+
+ assert 101 not in aws.functions
+
+ fout = a.fade_out
+ with pytest.raises(ValueError):
+ a.fade_out = -50
+ assert a.fade_out == fout
+
+ fin = a.fade_in
+ with pytest.raises(ValueError):
+ a.fade_in = -50
+ assert a.fade_in == fin
+
+ a._set_duration(10000)
+ assert a.copy_data(a.get_data()) is None
+
+ a.filename = None
+ assert a.duration == 0
+ assert a.actual_duration == 0
diff --git a/tests/test_functions_scene.py b/tests/test_functions_scene.py
index 7a5b78b..77b2d6f 100644
--- a/tests/test_functions_scene.py
+++ b/tests/test_functions_scene.py
@@ -1,7 +1,9 @@
import pytest
+import xml.etree.ElementTree as et
+
from blc2.functions.scene import Scene
-from blc2.constants import INFTY
+from blc2.constants import INFTY, BXW
def test_scene(aws):
"""Test creation and modification of scenes."""
@@ -74,3 +76,37 @@ def test_scene(aws):
lc, ac, _ = s1.render(1)
assert dict(lc)[c1] == 10
assert False not in (v == values[c] for c, v in lc if c != c1)
+
+ with pytest.raises(ValueError):
+ s1[c1] = -10
+ assert s1[c1] == 10
+
+ with pytest.raises(ValueError):
+ s1[c1] = -256
+ assert s1[c1] == 10
+
+ del s1[c4]
+ del s1[c4]
+
+def test_scene_serialize(aws, test_xml_eq):
+ return
+ c1, c2, c3, c4 = aws.fixtures[0].channels
+ s = Scene(aws, id_=123, name="Test Scene", values={c1: 1, c2: 2, c3: 3, c4: 4})
+
+ (f1, i1), (f2, i2), (f3, i3), (f4, i4) = ((i.f.id, i.id) for i in (c1, c2, c3, c4))
+
+ e = s.serialize()
+ expected = """
+<function xmlns="{bxw}" type="Scene" id="123" name="Test Scene">
+ <value fixture="{f1}" channel="{i1}">1</value>
+ <value fixture="{f2}" channel="{i2}">2</value>
+ <value fixture="{f3}" channel="{i3}">3</value>
+ <value fixture="{f4}" channel="{i4}">4</value>
+</function>
+""".format(bxw=BXW.strip("{}"), f1=f1, f2=f2, f3=f3, f4=f4, i1=i1,i2=i2,i3=i3,i4=i4)
+
+ et.register_namespace("", BXW)
+ print(et.tostring(e, encoding="utf-8"))
+ print(expected)
+
+ assert test_xml_eq(e, expected)