Exemple #1
0
def test_db_closed(path):
    with lmbd.DataStore(path, categories=10) as db:
        pass
    with pytest.raises(lmdb.Error) as error:
        db["a", "b"] = 1
    assert "Attempt to operate on closed/deleted/dropped object." == str(
        error.value)
Exemple #2
0
async def test_update_timestamp(path, monkeypatch):
    monkeypatch.setattr(config, "DATA_PATH", path)
    async with aiomoex.ISSClientSession():
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            date = await utils.update_timestamp(db)
            date_web = await utils.download_last_history()
            date_store = db[utils.LAST_HISTORY].value
    assert date == date_web == date_store
Exemple #3
0
def test_get(path):
    with lmbd.DataStore(path, categories=10) as db:
        assert db["aa"] == 1
        assert db["b"] == 2
        assert db["aa", "first"] == 3
        assert db["b", "first"] == 4

        db["c"] = 3
        assert db.stat()["entries"] == 4
        assert db.stat("first")["entries"] == 2
Exemple #4
0
async def test_update_timestamp_after_end_of_trading_day(path, monkeypatch):
    monkeypatch.setattr(config, "DATA_PATH", path)
    fake_end_of_trading = dict(hour=0,
                               minute=0,
                               second=0,
                               microsecond=0,
                               nanosecond=0)
    async with aiomoex.ISSClientSession():
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            date_web = await utils.download_last_history()
            monkeypatch.setattr(utils, "END_OF_TRADING", fake_end_of_trading)
            date = await utils.update_timestamp(db)
            date_store = db[utils.LAST_HISTORY].value
    assert date == date_web == date_store
Exemple #5
0
async def fake_data_path(path):
    async with aiomoex.ISSClientSession() as session:
        with lmbd.DataStore(path, MAX_SIZE, MAX_DBS) as db:
            manager.AbstractManager.ISS_SESSION = session
            manager.AbstractManager.STORE = db
            yield
Exemple #6
0
def open_store():
    """Открывает key-value хранилище."""
    return lmbd.DataStore(config.DATA_PATH, MAX_SIZE, MAX_DBS)
Exemple #7
0
def test_get_no_value(path):
    with lmbd.DataStore(path, categories=10) as db:
        assert db["dd"] is None