コード例 #1
0
ファイル: test_core.py プロジェクト: quantopian/chest
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()
コード例 #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)
コード例 #3
0
ファイル: test_core.py プロジェクト: mrocklin/chest
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)
コード例 #4
0
ファイル: test_core.py プロジェクト: quantopian/chest
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)
コード例 #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
コード例 #6
0
ファイル: test_core.py プロジェクト: quantopian/chest
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
コード例 #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]
コード例 #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()
コード例 #9
0
ファイル: test_core.py プロジェクト: quantopian/chest
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()