

def test_runnable():
    runnable = Runnable()
    with pytest.raises(NotImplementedError):
        runnable.start()

    class Implementation(Runnable):
        step = 1

        def run(self):
            self.step = 2
            (yield)
            self.step = 3
    runnable = Implementation()
    assert (runnable.step == 1)
    assert (not step.is_running())
    runnable.start()
    assert (runnable.step == 2)
    assert runnable.is_running()
    with pytest.raises(RuntimeError):
        runnable.start()
    runnable.stop()
    assert (runnable.step == 3)
    assert (not runnable.is_running())
    with pytest.raises(RuntimeError):
        runnable.stop()

    class NotYield(Runnable):

        def run(self):
            if False:
                (yield)
    runnable = NotYield()
    with pytest.raises(TypeError):
        runnable.start()

    class YieldSomething(Runnable):

        def run(self):
            (yield 123)
    runnable = YieldSomething()
    with pytest.raises(TypeError):
        runnable.start()

    class YieldTwice(Runnable):

        def run(self):
            (yield)
            (yield)
    runnable = YieldTwice()
    runnable.start()
    with pytest.raises(TypeError):
        runnable.stop()

dataset/ETHPy150Open what-studio/profiling/test/test_utils.py test_runnable/VarMisuse@90/108 `runnable`->`step`