Ejemplo n.º 1
0
def test_coiter_throw():
    c = coiter(co_throwable())
    assert next(c) == 1
    e = ValueError()
    assert c.throw(e) is e

    d = coiter((1, 2, 3))
    with pytest.raises(ValueError) as exc:
        d.throw(e)
    assert exc.value is e

    f = coiter((1, 2, 3))
    with pytest.raises(ValueError) as exc:
        f.throw(ValueError, 'v')
    assert exc.value.args == ('v', )
Ejemplo n.º 2
0
def test_coiter_throw():
    c = coiter(co_throwable())
    assert next(c) == 1
    e = ValueError()
    assert c.throw(e) is e

    d = coiter((1, 2, 3))
    with pytest.raises(ValueError) as exc:
        d.throw(e)
    assert exc.value is e

    f = coiter((1, 2, 3))
    with pytest.raises(ValueError) as exc:
        f.throw(ValueError, 'v')
    assert exc.value.args == ('v',)
Ejemplo n.º 3
0
def test_coiter_close():
    c = coiter(gen())
    assert next(c) == 1
    c.close()
    assert tuple(c) == ()
Ejemplo n.º 4
0
def test_coiter_iter():
    assert tuple(coiter((1, 2, 3))) == (1, 2, 3)
    it = coiter((1, 2, 3))
    for n in (1, 2, 3):
        assert it.send(None) == n
Ejemplo n.º 5
0
def test_coiter_send():
    c = coiter(co())
    assert next(c) == 1
    for n in (2, 3):
        assert c.send(n) == n
Ejemplo n.º 6
0
def test_coiter_close():
    c = coiter(gen())
    assert next(c) == 1
    c.close()
    assert tuple(c) == ()
Ejemplo n.º 7
0
def test_coiter_iter():
    assert tuple(coiter((1, 2, 3))) == (1, 2, 3)
    it = coiter((1, 2, 3))
    for n in (1, 2, 3):
        assert it.send(None) == n
Ejemplo n.º 8
0
def test_coiter_send():
    c = coiter(co())
    assert next(c) == 1
    for n in (2, 3):
        assert c.send(n) == n