Exemplo n.º 1
0
    def test_trampoline_schedule(self):
        scheduler = TrampolineScheduler()
        ran = False

        def action(scheduler, state=None):
            nonlocal ran
            ran = True

        scheduler.schedule(action)
        assert ran is True
Exemplo n.º 2
0
    def test_trampoline_schedule_error(self):
        scheduler = TrampolineScheduler()

        class MyException(Exception):
            pass

        def action(scheduler, state=None):
            raise MyException()

        with pytest.raises(MyException):
            scheduler.schedule(action)
Exemplo n.º 3
0
    def test_trampoline_schedule_nested(self):
        scheduler = TrampolineScheduler()
        ran = False

        def action(scheduler, state=None):
            def inner_action(scheduler, state=None):
                nonlocal ran
                ran = True

            return scheduler.schedule(inner_action)
        scheduler.schedule(action)

        assert ran is True
        def outer(scheduler, state=None):
            def action1(scheduler, state=None):
                tests.append(1)

                def action2(scheduler, state=None):
                    tests.append(2)

                TrampolineScheduler().schedule(action2)

            TrampolineScheduler().schedule(action1)

            def action3(scheduler, state=None):
                tests.append(3)

            scheduler3 = TrampolineScheduler()
            scheduler3.schedule(action3)