nancy/tests/test_store.py
Jacob Hinkle 8e69ca3390 Many changes to keys and move persist() to fs.py
This fixes a lot of awkwardness that came from having the record()
functionality inside of store.py. It is still broken, but is much closer
to actually working now. I also sketched some data and io functionality,
which has no tests and is not yet working at all.
2022-10-11 12:27:40 -04:00

49 lines
1.3 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 empty 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(bare_dir: Path) -> Iterator[store.Store]:
s = store.Store.init(directory=bare_dir, 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