Ejemplo n.º 1
0
def test_write_values():
    tst = "foobarvoing"
    s = StringIO()
    writer.write_values(s, [tst], [])
    assert s.getvalue() == tst

    for bs in range(1, len(tst) + 2):
        for off in range(len(tst)):
            s = StringIO()
            writer.write_values(s, [tst], [(off, "disconnect")], blocksize=bs)
            assert s.getvalue() == tst[:off]
Ejemplo n.º 2
0
def test_write_values():
    tst = "foobarvoing"
    s = cStringIO.StringIO()
    writer.write_values(s, [tst], [])
    assert s.getvalue() == tst

    for bs in range(1, len(tst) + 2):
        for off in range(len(tst)):
            s = cStringIO.StringIO()
            writer.write_values(s, [tst], [(off, "disconnect")], blocksize=bs)
            assert s.getvalue() == tst[:off]
Ejemplo n.º 3
0
def test_write_values_inject():
    tst = "foo"

    s = cStringIO.StringIO()
    writer.write_values(s, [tst], [(0, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "aaafoo"

    s = cStringIO.StringIO()
    writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "faaaoo"

    s = cStringIO.StringIO()
    writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "faaaoo"
Ejemplo n.º 4
0
def test_write_values_inject():
    tst = "foo"

    s = StringIO()
    writer.write_values(s, [tst], [(0, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "aaafoo"

    s = StringIO()
    writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "faaaoo"

    s = StringIO()
    writer.write_values(s, [tst], [(1, "inject", "aaa")], blocksize=5)
    assert s.getvalue() == "faaaoo"
Ejemplo n.º 5
0
def test_write_values_inject():
    tst = b"foo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(0, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"aaafoo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"faaaoo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"faaaoo"
Ejemplo n.º 6
0
def test_write_values_inject():
    tst = b"foo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(0, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"aaafoo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"faaaoo"

    s = io.BytesIO()
    writer.write_values(s, [tst], [(1, "inject", b"aaa")], blocksize=5)
    assert s.getvalue() == b"faaaoo"
Ejemplo n.º 7
0
def test_write_values_pauses():
    tst = "".join(str(i) for i in range(10))
    for i in range(2, 10):
        s = StringIO()
        writer.write_values(s, [tst], [(2, "pause", 0), (1, "pause", 0)], blocksize=i)
        assert s.getvalue() == tst

    for i in range(2, 10):
        s = StringIO()
        writer.write_values(s, [tst], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == tst

    tst = ["".join(str(i) for i in range(10))] * 5
    for i in range(2, 10):
        s = StringIO()
        writer.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == "".join(tst)
Ejemplo n.º 8
0
def test_write_values_pauses():
    tst = "".join(str(i) for i in range(10))
    for i in range(2, 10):
        s = cStringIO.StringIO()
        writer.write_values(s, [tst], [(2, "pause", 0), (1, "pause", 0)],
                            blocksize=i)
        assert s.getvalue() == tst

    for i in range(2, 10):
        s = cStringIO.StringIO()
        writer.write_values(s, [tst], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == tst

    tst = ["".join(str(i) for i in range(10))] * 5
    for i in range(2, 10):
        s = cStringIO.StringIO()
        writer.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == "".join(tst)
Ejemplo n.º 9
0
def test_write_values_pauses():
    tst = "".join(str(i) for i in range(10)).encode()
    for i in range(2, 10):
        s = io.BytesIO()
        writer.write_values(s, [tst], [(2, "pause", 0), (1, "pause", 0)],
                            blocksize=i)
        assert s.getvalue() == tst

    for i in range(2, 10):
        s = io.BytesIO()
        writer.write_values(s, [tst], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == tst

    tst = [tst] * 5
    for i in range(2, 10):
        s = io.BytesIO()
        writer.write_values(s, tst[:], [(1, "pause", 0)], blocksize=i)
        assert s.getvalue() == b"".join(tst)
Ejemplo n.º 10
0
def test_write_values_disconnects():
    s = cStringIO.StringIO()
    tst = "foo" * 100
    writer.write_values(s, [tst], [(0, "disconnect")], blocksize=5)
    assert not s.getvalue()
Ejemplo n.º 11
0
def test_write_values_disconnects():
    s = StringIO()
    tst = "foo" * 100
    writer.write_values(s, [tst], [(0, "disconnect")], blocksize=5)
    assert not s.getvalue()
Ejemplo n.º 12
0
def test_write_values_disconnects():
    s = io.BytesIO()
    tst = b"foo" * 100
    writer.write_values(s, [tst], [(0, "disconnect")], blocksize=5)
    assert not s.getvalue()