Ejemplo n.º 1
0
def test_recreate_chest():
    with tmp_chest() as c:
        c[1] = 'one'
        c[2] = 'two'

        c.flush()

        c2 = Chest(path=c.path)

        assert c.items() == c2.items()
Ejemplo n.º 2
0
def test_del_on_temp_path():
    c = Chest()
    c[1] = 'one'
    c.flush()

    fn = c.path
    del c

    import gc
    gc.collect()

    assert not os.path.exists(fn)
Ejemplo n.º 3
0
def test_context_manager():
    with Chest() as c:
        c[1] = 1
        c.flush()

    assert not os.path.exists(c.path)

    try:
        with Chest() as c:
            1 / 0
    except Exception as e:
        assert isinstance(e, ZeroDivisionError)
Ejemplo n.º 4
0
def test_del_on_temp_path():
    c = Chest()
    c[1] = 'one'
    c.flush()

    fn = c.path
    del c

    import gc
    gc.collect()

    assert not os.path.exists(fn)
Ejemplo n.º 5
0
def tmp_chest(*args, **kwargs):
    c = Chest(*args, **kwargs)
    fn = c.path

    try:
        yield c
    finally:
        if os.path.exists(fn):
            with c.lock:
                c.drop()
        try:
            del c
        except:
            pass
Ejemplo n.º 6
0
def tmp_chest(*args, **kwargs):
    c = Chest(*args, **kwargs)
    fn = c.path

    try:
        yield c
    finally:
        if os.path.exists(fn):
            with c.lock:
                c.drop()
        try:
            del c
        except:
            pass
Ejemplo n.º 7
0
def test_basic_json():
    with tmp_chest(load=json.load, dump=json.dump, mode='t') as c:
        c[1] = [1, 2, 3]
        c[2] = 'two'

        c.flush()

        c2 = Chest(path=c.path, load=json.load, dump=json.dump, mode='t')

        assert c2[1] == c[1]
        assert c2[2] == c[2]
Ejemplo n.º 8
0
def test_del_on_normal_path():
    path = '_chest_test_path'
    if os.path.exists(path):
        shutil.rmtree(path)

    c = Chest(path=path)
    c[1] = 'one'
    c.flush()

    del c
    import gc
    gc.collect()

    assert os.path.exists(path)

    c = Chest(path=path)
    c.drop()
Ejemplo n.º 9
0
def test_del_on_normal_path():
    path = '_chest_test_path'
    if os.path.exists(path):
        shutil.rmtree(path)

    c = Chest(path=path)
    c[1] = 'one'
    c.flush()

    del c
    import gc
    gc.collect()

    assert os.path.exists(path)

    c = Chest(path=path)
    c.drop()