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

Log | Files | Refs

test_functions_chaserstep.py (4800B) - raw


      1 import datetime as dt
      2 
      3 import pytest
      4 
      5 from blc2.functions.chaserstep import ChaserStep
      6 from blc2.topology import Fixture
      7 from blc2.functions.scene import Scene
      8 from blc2.functions.audio import Audio
      9 from blc2.workspace import Workspace
     10 from blc2.constants import INHERIT, MANUAL, EXTERNAL, INTERNAL, INFTY
     11 
     12 class DummyChaser:
     13     def register_step(self, *args, **kwargs):
     14         if self.throw:
     15             raise Exception("blah")
     16         self.count += 1
     17 
     18     def delete_step(self, *args, **kwargs):
     19         self.count -= 1
     20 
     21     def __init__(self, w):
     22         self.w = w
     23         self.count = 0
     24         self.throw = False
     25 
     26 @pytest.fixture
     27 def cw():
     28     w = Workspace("", "", "", dt.datetime.now())
     29     f = Fixture(w=w, id_=0, channel_count=1)
     30     c0, = f.channels
     31     f2 = Fixture(w=w, id_=1, channel_count=4)
     32     Scene(w=w, id_=0, values={c0: 255})
     33     Scene(w=w, id_=1, values={c: 255-i for i, c in enumerate(f2.channels)})
     34     Audio(w=w, id_=2, filename="tests/silence.m4a")
     35 
     36     return w
     37 
     38 def test_chaserstep(cw):
     39     c = DummyChaser(cw)
     40     s0 = cw.functions[0]
     41     s1 = cw.functions[1]
     42     a = cw.functions[2]
     43     c0, = cw.fixtures[0].channels
     44 
     45     ## Try adding a negative index
     46     with pytest.raises(Exception):
     47         ChaserStep(c, id_=42069, function=s0, duration_mode=INHERIT, index=-10)
     48     assert c.count == 0
     49     assert 42069 not in cw.functions
     50 
     51     ## Test a failed add
     52     with pytest.raises(Exception):
     53         c.throw = True
     54         ChaserStep(c, id_=42069, function=s0, duration_mode=INHERIT)
     55     assert 42069 not in cw.functions
     56     c.throw = False
     57 
     58     ## Test how it handles inherit
     59     cs1 = ChaserStep(c, function=s0, duration_mode=INHERIT)
     60     assert cs1.duration == INFTY
     61     assert cs1.actual_duration == INFTY
     62     assert cs1.duration_mode == INHERIT
     63     assert cs1.fade_out_mode == s0.fade_out_mode
     64     assert cs1.scope == s0.scope
     65     assert cs1.audio_scope == s0.audio_scope
     66 
     67     cs1.fade_in = 1000
     68     cs1.fade_out = 1000
     69     assert cs1.duration == INFTY
     70     assert cs1.actual_duration == INFTY
     71 
     72     data = cs1._get_data(0, 0)
     73     lc, ac, data = cs1.render(500, data)
     74     assert not ac
     75     assert lc == ((c0, 127),)
     76 
     77     lc, ac, data = cs1.render(1000, data)
     78     assert not ac
     79     assert lc == ((c0, 255),)
     80 
     81     data.end_time = 1500
     82     lc, ac, data = cs1.render(2000, data)
     83     assert not ac
     84     assert lc == ((c0, 127),)
     85 
     86     lc, ac, data = cs1.render(2501, data)
     87     assert not ac
     88     assert not lc
     89 
     90     ## Test how it handles manual mode
     91     cs1.duration_mode = MANUAL
     92     cs1.duration = 1500
     93     assert cs1.duration == 1500
     94     assert cs1.actual_duration == 2500
     95 
     96     data = cs1._get_data(0, 0)
     97     lc, ac, data = cs1.render(500, data)
     98     assert not ac
     99     assert lc == ((c0, 127),)
    100 
    101     lc, ac, data = cs1.render(1000, data)
    102     assert not ac
    103     assert lc == ((c0, 255),)
    104 
    105     lc, ac, data = cs1.render(2000, data)
    106     assert not ac 
    107     assert lc == ((c0, 127),)
    108 
    109     lc, ac, data = cs1.render(2501, data)
    110     assert not ac
    111     assert not lc
    112 
    113     ## Test how it handles inherit and a function change
    114     cs1.duration_mode = INHERIT
    115     assert cs1.duration == INFTY
    116     assert cs1.actual_duration == INFTY
    117 
    118     data = cs1._get_data(0, 0)
    119     
    120     cs1.fade_out = 0
    121     cs1.fade_in = 0
    122     cs1.function = a
    123     if a.actual_duration != 3024:
    124         raise ValueError("silence.m4a is wrong duration, fix the tests")
    125     assert cs1.audio_scope == a.audio_scope
    126     assert cs1.scope == a.scope
    127     assert cs1.duration == a.actual_duration
    128     assert cs1.actual_duration == a.actual_duration
    129     cs1.fade_out = 1000
    130     cs1.fade_in = 1000
    131     assert cs1.duration == a.actual_duration-1000
    132 
    133     lc, ac, data = cs1.render(500, data)
    134     assert not lc
    135     assert len(ac) == 1
    136     assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 2024, 1000)
    137     a.fade_out = 2000
    138     lc, ac, data = cs1.render(501, data)
    139     assert not lc
    140     assert len(ac) == 1
    141     assert ac[0][1:] == ("tests/silence.m4a", 0, 1000, 1024, 2000)
    142 
    143     lc, ac, data = cs1.render(3025, data)
    144     assert not lc
    145     assert not ac
    146 
    147     cs1.function = None
    148     assert cs1.duration == 0
    149     assert cs1.actual_duration == 0
    150 
    151     cs1.fade_in = 100
    152     with pytest.raises(ValueError):
    153         cs1.fade_in = -100
    154     assert cs1.fade_in == 100
    155 
    156     cs1.fade_out = 100
    157     with pytest.raises(ValueError):
    158         cs1.fade_out = -100
    159     assert cs1.fade_out == 100
    160 
    161     cs1.function = s0
    162     s0.delete()
    163     assert cs1.function is None
    164     assert cs1.audio_scope == frozenset()
    165     assert cs1.scope == frozenset()
    166     cs1.duration_mode = INHERIT
    167     with pytest.raises(AttributeError):
    168         cs1.duration = 50
    169     assert cs1.render(10000, data)[:2] == ((), ())
    170 
    171     cs1.duration_mode = MANUAL
    172     cs1.duration = 500
    173     with pytest.raises(ValueError):
    174         cs1.duration = -100
    175     assert cs1.duration == 500
    176 
    177