Exemplo n.º 1
0
def test_throw_finished():
    def task():
        try:
            yield
        except IndexError:
            pass

    fiber = Fiber(task)
    fiber.switch()
    with raises(StopIteration):
        fiber.throw(IndexError)
Exemplo n.º 2
0
def test_throw_unfinished():
    def task():
        try:
            yield
            array.append(1)
        except IndexError:
            array.append(2)
            yield

    array = []
    fiber = Fiber(task)
    fiber.switch()
    fiber.throw(IndexError)
    assert array == [2]
    assert not fiber.done