Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_nested(self):
results = []
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', lambda : results.append('b ran')),
)
assert cs.count == 2
cs2 = CallSequence(
('c', cs),
)
assert cs2.count == 1
cs2.invoke()
assert results == ['a ran', 'b ran']
def test_replace(self):
results = []
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', lambda : results.append('b ran')),
)
assert cs.count == 2
cs.replace_task('b', lambda : results.append('wheee'))
cs()
assert results == ['a ran', 'wheee']
def test_insert_after_4(self):
cs = CallSequence()
with pytest.raises(KeyError):
cs.insert_after('z', ('c', lambda : results.append('c ran')))
def test_wrap(self):
results = []
def task_b():
results.append('b ran')
return "task b result"
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', task_b),
)
assert cs.count == 2
def wrapper(t):
assert t == "task b result"
results.append('wrapper ran')
cs.wrap_task('b', wrapper)
cs()
assert results == ['a ran', 'b ran', 'wrapper ran']
def test_insert_before_3(self):
results = []
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', lambda : results.append('b ran')),
)
assert cs.count == 2
cs.insert_before('a', ('c', lambda : results.append('c ran')),
('d', lambda : results.append('d ran')))
assert cs.count == 4
cs()
assert results == ['c ran', 'd ran', 'a ran', 'b ran']
def test_append_2(self):
results = []
cs = CallSequence(
('a', lambda : results.append('a ran')),
)
assert cs.count == 1
cs.append(
('b', lambda : results.append('b ran')),
('c', lambda : results.append('c ran')),
)
assert cs.count == 3
cs.invoke()
assert results == ['a ran', 'b ran', 'c ran']
def test_insert_after_1(self):
results = []
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', lambda : results.append('b ran')),
)
assert cs.count == 2
cs.insert_after('b', ('c', lambda : results.append('c ran')))
assert cs.count == 3
cs()
assert results == ['a ran', 'b ran', 'c ran']
def test_returned_seq(self):
results = []
def task_b():
results.append('b ran')
cs2 = CallSequence(
('x', lambda : results.append('x ran')),
('y', lambda : results.append('y ran')),
)
assert cs2.count == 2
return cs2
cs = CallSequence(
('a', lambda : results.append('a ran')),
('b', task_b),
('c', lambda : results.append('c ran')),
)
assert cs.count == 3
cs()
assert results == ['a ran', 'b ran', 'x ran', 'y ran', 'c ran']
def create_aps(self):
seq = CallSequence()
for ap_num in self.valid_aps:
seq.append(
('create_ap.{}'.format(ap_num), lambda ap_num=ap_num: self.create_1_ap(ap_num))
)
return seq