Пример #1
0
 def test_clear(self):
     cs = CallSequence(
         ('a', lambda: results.append('a ran')),
         ('b', lambda: results.append('b ran')),
     )
     assert cs.count == 2
     cs.clear()
     assert cs.count == 0
Пример #2
0
 def test_a(self):
     results = []
     cs = CallSequence(
         ('a', lambda: results.append('a ran')),
         ('b', lambda: results.append('b ran')),
     )
     assert cs.count == 2
     cs.invoke()
     assert results == ['a ran', 'b ran']
Пример #3
0
 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']
Пример #4
0
 def test_insert_after_2(self):
     results = []
     cs = CallSequence(
         ('a', lambda: results.append('a ran')),
         ('b', lambda: results.append('b ran')),
     )
     assert cs.count == 2
     cs.insert_after('a', ('c', lambda: results.append('c ran')))
     assert cs.count == 3
     cs()
     assert results == ['a ran', 'c ran', 'b ran']
Пример #5
0
    def test_get(self):
        results = []

        def task_a():
            results.append('a ran')

        cs = CallSequence(('a', task_a), )
        assert cs.count == 1
        assert cs.get_task('a') == task_a
        with pytest.raises(KeyError):
            cs.get_task('foo')
Пример #6
0
 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']
Пример #7
0
 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
Пример #8
0
    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']
Пример #9
0
    def test_remove_1(self):
        results = []
        cs = CallSequence(
            ('a', lambda: results.append('a ran')),
            ('b', lambda: results.append('b ran')),
        )
        assert cs.count == 2

        cs.remove_task('b')
        assert cs.count == 1

        cs.invoke()
        assert results == ['a ran']
Пример #10
0
    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']
Пример #11
0
    def test_iter(self):
        results = []

        def task_a():
            results.append('a ran')

        def task_b():
            results.append('b ran')

        cs = CallSequence(
            ('a', task_a),
            ('b', task_b),
        )
        assert cs.count == 2
        it = iter(cs)
        print("it=", repr(it), dir(it))
        assert six.next(it) == ('a', task_a)
        assert six.next(it) == ('b', task_b)
        with pytest.raises(StopIteration):
            six.next(it)
Пример #12
0
 def test_insert_after_4(self):
     cs = CallSequence()
     with pytest.raises(KeyError):
         cs.insert_after('z', ('c', lambda: results.append('c ran')))
Пример #13
0
 def test_empty(self):
     cs = CallSequence()
     assert cs.count == 0
Пример #14
0
 def test_has(self):
     cs = CallSequence(('a', lambda: results.append('a ran')), )
     assert cs.count == 1
     assert cs.has_task('a')
     assert not cs.has_task('foo')