Exemplo n.º 1
0
def test_cozip_ziplike():
    cz = cozip((1, 2, 3), (1, 2, 3))
    assert isinstance(cz, zip)
    assert tuple(cz) == tuple(zip((1, 2, 3), (1, 2, 3))) == (
        (1, 1), (2, 2), (3, 3),
    )

    dz = cozip((1, 2, 3))
    assert tuple(dz) == tuple(zip((1, 2, 3))) == ((1,), (2,), (3,))
Exemplo n.º 2
0
def test_cozip_close():
    cz = cozip(gen())
    assert next(cz) == (1,)
    cz.close()
    assert tuple(cz) == ()

    dz = cozip(gen(), gen())
    assert next(dz) == (1, 1)
    dz.close()
    assert tuple(dz) == ()
Exemplo n.º 3
0
def test_cozip_send():
    cz = cozip(co())
    assert next(cz) == (1,)
    for n in (2, 3):
        assert cz.send(n) == (n,)

    dz = cozip(co(), co())
    assert next(dz) == (1, 1)
    for n in (2, 3):
        assert dz.send(n) == (n, n)
Exemplo n.º 4
0
def test_cozip_throw():
    cz = cozip(co_throwable())
    assert next(cz) == (1,)
    e = ValueError()
    assert cz.throw(e) == (e,)

    dz = cozip(co_throwable(), co_throwable())
    assert next(dz) == (1, 1)
    e = ValueError()
    assert dz.throw(e) == (e, e)

    ez = cozip(co_throwable(), gen())
    assert next(ez) == (1, 1)
    with pytest.raises(ValueError) as exc:
        ez.throw(e)
    assert exc.value is e