From 08424555f82bad0831e4ffad6cac68950512be8e Mon Sep 17 00:00:00 2001 From: Ben Connors Date: Sun, 29 Sep 2019 17:58:03 -0400 Subject: Some fixes - Remove print statements - Fix chaser scope and rendering --- blc2/functions/chaser.py | 6 +++-- examples/workspace.xml | 29 ++++++++++++++------ tests/conftest.py | 5 ---- tests/test_functions_audio.py | 24 +++++++++++++++++ tests/test_functions_chaserstep.py | 55 +++++++++++++++++++++++++++++++++++++- 5 files changed, 103 insertions(+), 16 deletions(-) diff --git a/blc2/functions/chaser.py b/blc2/functions/chaser.py index fe6fc17..c63f8c4 100644 --- a/blc2/functions/chaser.py +++ b/blc2/functions/chaser.py @@ -112,7 +112,6 @@ class Chaser(Function): def next_steps(self, data): """Iterate over the next steps in the chaser.""" n = data.steps[-1].index - print("Last index", n) if self._advance_mode == RANDOM: while True: yield random.randint(0, len(self.steps)-1) @@ -140,6 +139,7 @@ class Chaser(Function): self._steps.insert(step.index, step) self.w.register_function_delete_callback(step, self._step_deleted, self) self._fix_indices() + self._recalculate() def move_step(self, step, position): """Move a step around.""" @@ -239,7 +239,9 @@ class Chaser(Function): for n, d in enumerate(data.steps): s = d.step slc, sac, data.steps[n] = s.render(t, data=d) - lc.update(slc) + for c, v in slc: + if lc[c] < v: + lc[c] = v ac.extend(sac) return tuple(lc.items()), ac, data diff --git a/examples/workspace.xml b/examples/workspace.xml index c30e8ef..257c777 100644 --- a/examples/workspace.xml +++ b/examples/workspace.xml @@ -25,17 +25,30 @@ - - 127 - 127 - 127 + + 255 + 0 + 0 - + + 0 + 255 + 0 + + + + 0 + 0 + 255 + + + - - - + + + + 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 = [ + """""", + """""", + """""", + """""", + """""", + ] + + for case in fail: + case = case.format('"'+BXW.strip("{}")+'"') + with pytest.raises(LoadError): + Audio.deserialize(aws, et.fromstring(case)) + + case = """""" + 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 + + -- cgit v1.2.3