summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Connors <benconnors@outlook.com>2019-09-29 17:58:03 -0400
committerBen Connors <benconnors@outlook.com>2019-09-29 17:58:19 -0400
commit08424555f82bad0831e4ffad6cac68950512be8e (patch)
treec9f59407e87a7e0b8f5b41df439f7120e6044205 /tests
parent2255278b0e81fc20faff48536f524e1466046c8a (diff)
Some fixes
- Remove print statements - Fix chaser scope and rendering
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py5
-rw-r--r--tests/test_functions_audio.py24
-rw-r--r--tests/test_functions_chaserstep.py55
3 files changed, 78 insertions, 6 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 896a2ba..ebc9855 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -21,19 +21,14 @@ def aws():
def elements_equal(e1, e2):
"""Determine if two XML elements are equal."""
if e1.tag != e2.tag:
- print("tag", e1.tag, e2.tag)
return False
if ("" if e1.text is None else e1.text).strip("\r\n\t ") != ("" if e2.text is None else e2.text).strip("\r\n\t "):
- print("text", repr(e1.text), repr(e2.text))
return False
if ("" if e1.tail is None else e1.tail).strip("\r\n\t ") != ("" if e2.tail is None else e2.tail).strip("\r\n\t "):
- print("tail", repr(e1.tail), repr(e2.tail))
return False
if e1.attrib != e2.attrib:
- print("attrib", repr(e1.attrib), repr(e2.attrib))
return False
if len(e1) != len(e2):
- print("len", len(e1), len(e2))
return False
return all(elements_equal(c1, c2) for c1, c2 in zip(e1, e2))
diff --git a/tests/test_functions_audio.py b/tests/test_functions_audio.py
index 5aaec5a..b6e6c6a 100644
--- a/tests/test_functions_audio.py
+++ b/tests/test_functions_audio.py
@@ -1,9 +1,12 @@
"""Tests for the audio primitive."""
+import xml.etree.ElementTree as et
+
import pytest
from blc2.functions.audio import Audio
from blc2.constants import BXW
+from blc2.exceptions import LoadError
def test_audio(aws):
a = Audio(aws)
@@ -76,3 +79,24 @@ def test_audio_serialize(aws, test_xml_eq):
for case, s in zip(test, success):
s = s.replace('\n', "").format(BXW.strip("{}"))
assert test_xml_eq(case.serialize(), s)
+
+def test_audio_deserialize(aws, test_xml_eq):
+ fail = [
+ """<function xmlns={} type="asdf"/>""",
+ """<asdf/>""",
+ """<function xmlns={} type="Audio" id="asdf"/>""",
+ """<function xmlns={} type="Audio" id="123" name="Test Audio" fade-out="asdf"/>""",
+ """<function xmlns={} type="Audio" id="123" name="Test Audio" fade-in="asdf"/>""",
+ ]
+
+ for case in fail:
+ case = case.format('"'+BXW.strip("{}")+'"')
+ with pytest.raises(LoadError):
+ Audio.deserialize(aws, et.fromstring(case))
+
+ case = """<function xmlns={} type="Audio" id="123" name="Test Audio" fade-in="123" fade-out="321" filename="test.wav"/>"""
+ case = case.format('"'+BXW.strip("{}")+'"')
+
+ s = Audio.deserialize(aws, et.fromstring(case))
+
+ assert test_xml_eq(s.serialize(), case)
diff --git a/tests/test_functions_chaserstep.py b/tests/test_functions_chaserstep.py
index 134b893..6185f46 100644
--- a/tests/test_functions_chaserstep.py
+++ b/tests/test_functions_chaserstep.py
@@ -11,10 +11,17 @@ from blc2.constants import INHERIT, MANUAL, EXTERNAL, INTERNAL, INFTY
class DummyChaser:
def register_step(self, *args, **kwargs):
- return
+ if self.throw:
+ raise Exception("blah")
+ self.count += 1
+
+ def delete_step(self, *args, **kwargs):
+ self.count -= 1
def __init__(self, w):
self.w = w
+ self.count = 0
+ self.throw = False
@pytest.fixture
def cw():
@@ -35,10 +42,24 @@ def test_chaserstep(cw):
a = cw.functions[2]
c0, = cw.fixtures[0].channels
+ ## Try adding a negative index
+ with pytest.raises(Exception):
+ ChaserStep(c, id_=42069, function=s0, duration_mode=INHERIT, index=-10)
+ assert c.count == 0
+ assert 42069 not in cw.functions
+
+ ## Test a failed add
+ with pytest.raises(Exception):
+ c.throw = True
+ ChaserStep(c, id_=42069, function=s0, duration_mode=INHERIT)
+ assert 42069 not in cw.functions
+ c.throw = False
+
## Test how it handles inherit
cs1 = ChaserStep(c, function=s0, duration_mode=INHERIT)
assert cs1.duration == INFTY
assert cs1.actual_duration == INFTY
+ assert cs1.duration_mode == INHERIT
assert cs1.fade_out_mode == s0.fade_out_mode
assert cs1.scope == s0.scope
assert cs1.audio_scope == s0.audio_scope
@@ -122,3 +143,35 @@ def test_chaserstep(cw):
lc, ac, data = cs1.render(3025, data)
assert not lc
assert not ac
+
+ cs1.function = None
+ assert cs1.duration == 0
+ assert cs1.actual_duration == 0
+
+ cs1.fade_in = 100
+ with pytest.raises(ValueError):
+ cs1.fade_in = -100
+ assert cs1.fade_in == 100
+
+ cs1.fade_out = 100
+ with pytest.raises(ValueError):
+ cs1.fade_out = -100
+ assert cs1.fade_out == 100
+
+ cs1.function = s0
+ s0.delete()
+ assert cs1.function is None
+ assert cs1.audio_scope == frozenset()
+ assert cs1.scope == frozenset()
+ cs1.duration_mode = INHERIT
+ with pytest.raises(AttributeError):
+ cs1.duration = 50
+ assert cs1.render(10000, data)[:2] == ((), ())
+
+ cs1.duration_mode = MANUAL
+ cs1.duration = 500
+ with pytest.raises(ValueError):
+ cs1.duration = -100
+ assert cs1.duration == 500
+
+