1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
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):
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():
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
## 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
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
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
|