nancy/tests/test_store.py
Jacob Hinkle 07ccef601c Change to using UUID and SHA256 as DB keys
This is important for distributed settings, and will make merging
databases much simpler. This change is pretty extensive and includes a
lot of other stuff like moving some fields between tables, and
introducing the `local_metadata` table which is a key-value store and
holds the uuid of the "local" store, i.e. the one corresponding to the
directory holding that particular nancy.db.
2022-10-10 15:14:47 -04:00

49 lines
1.2 KiB
Python

"""Test functionality of the Store class."""
from nancy import store
import os
from pathlib import Path
import pytest
import sys
import tempfile
from typing import Iterator
@pytest.fixture
def bare_dir() -> Iterator[Path]:
"""Create an emptry temp directory"""
with tempfile.TemporaryDirectory(prefix="nancy_testdir") as d:
yield Path(d)
@pytest.fixture
def filled_dir(bare_dir: Path) -> Path:
open(bare_dir / "a.txt", "w").write("foo")
os.makedirs(bare_dir / "stats")
open(bare_dir / "stats" / "metrics.csv", "w").write("bar,baz")
# identical to ./a.txt
open(bare_dir / "stats" / "a.txt", "w").write("foo")
return bare_dir
def test_record_untracked_dir(filled_dir: Path) -> None:
from nancy.cli.record import record
record(store_path=filled_dir, message="test_record_untracked_dir")
@pytest.fixture
def empty_store() -> Iterator[store.Store]:
s = store.Store.init(message="test init")
yield s
def test_schema_version_match(empty_store: store.Store) -> None:
from nancy.version import schema_version
assert empty_store.conn is not None
cur = empty_store.conn.cursor()
(db_schema_ver,) = cur.execute("PRAGMA user_version;").fetchone()
assert schema_version == db_schema_ver