Ejemplo n.º 1
0
def test_bytearray(fn):
    data = bytearray(b"123")
    with Zip(fn) as z:
        z["x"] = data

    with Zip(fn) as z:
        assert z["x"] == b"123"
Ejemplo n.º 2
0
def test_bytearray(fn):
    data = bytearray(b'123')
    with Zip(fn) as z:
        z['x'] = data

    with Zip(fn) as z:
        assert z['x'] == b'123'
Ejemplo n.º 3
0
def test_close(fn):
    z = Zip(fn)

    z["x"] = b"123"
    z.close()

    zz = zipfile.ZipFile(fn, mode="r")
    assert zz.read("x") == b"123"

    with pytest.raises(IOError):
        z["y"] = b"123"
Ejemplo n.º 4
0
def test_close(fn):
    z = Zip(fn)

    z['x'] = b'123'
    z.close()

    zz = zipfile.ZipFile(fn, mode='r')
    assert zz.read('x') == b'123'

    with pytest.raises(IOError):
        z['y'] = b'123'
Ejemplo n.º 5
0
def test_close(fn):
    z = Zip(fn)

    z['x'] = b'123'
    z.close()

    zz = zipfile.ZipFile(fn, mode='r')
    assert zz.read('x') == b'123'

    with pytest.raises(IOError):
        z['y'] = b'123'
Ejemplo n.º 6
0
def test_simple(fn):
    z = Zip(fn)
    assert isinstance(z, MutableMapping)
    assert not z

    assert list(z) == list(z.keys()) == []
    assert list(z.values()) == []
    assert list(z.items()) == []

    z["x"] = b"123"
    assert list(z) == list(z.keys()) == ["x"]
    assert list(z.values()) == [b"123"]
    assert list(z.items()) == [("x", b"123")]
    assert z["x"] == b"123"

    z.flush()
    zz = zipfile.ZipFile(fn, mode="r")
    assert zz.read("x") == b"123"

    z["y"] = b"456"
    assert z["y"] == b"456"
Ejemplo n.º 7
0
def test_simple(fn):
    z = Zip(fn)
    assert isinstance(z, MutableMapping)
    assert not z

    assert list(z) == list(z.keys()) == []
    assert list(z.values()) == []
    assert list(z.items()) == []

    z['x'] = b'123'
    assert list(z) == list(z.keys()) == ['x']
    assert list(z.values()) == [b'123']
    assert list(z.items()) == [('x', b'123')]
    assert z['x'] == b'123'

    z.flush()
    zz = zipfile.ZipFile(fn, mode='r')
    assert zz.read('x') == b'123'

    z['y'] = b'456'
    assert z['y'] == b'456'
Ejemplo n.º 8
0
def test_simple(fn):
    z = Zip(fn)
    assert isinstance(z, MutableMapping)
    assert not z

    assert list(z) == list(z.keys()) == []
    assert list(z.values()) == []
    assert list(z.items()) == []

    z['x'] = b'123'
    assert list(z) == list(z.keys()) == ['x']
    assert list(z.values()) == [b'123']
    assert list(z.items()) == [('x', b'123')]
    assert z['x'] == b'123'

    z.flush()
    zz = zipfile.ZipFile(fn, mode='r')
    assert zz.read('x') == b'123'

    z['y'] = b'456'
    assert z['y'] == b'456'
Ejemplo n.º 9
0
def test_missing_key(fn):
    z = Zip(fn)

    with pytest.raises(KeyError):
        z["x"]
Ejemplo n.º 10
0
def test_contextmanager(fn):
    with Zip(fn) as z:
        z["x"] = b"123"

    zz = zipfile.ZipFile(fn, mode="r")
    assert zz.read("x") == b"123"
Ejemplo n.º 11
0
def test_setitem_typeerror(fn):
    z = Zip(fn)
    with pytest.raises(TypeError):
        z["x"] = 123
Ejemplo n.º 12
0
def test_contextmanager(fn):
    with Zip(fn) as z:
        z['x'] = b'123'

    zz = zipfile.ZipFile(fn, mode='r')
    assert zz.read('x') == b'123'