1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
import lzma
from pathlib import Path
import pytest
import wn
@pytest.fixture(scope="session")
def datadir():
return Path(__file__).parent / "data"
@pytest.fixture
def uninitialized_datadir(monkeypatch, tmp_path: Path):
with monkeypatch.context() as m:
m.setattr(wn.config, "data_directory", tmp_path / "uninitialized_datadir")
yield
@pytest.fixture(scope="session")
def empty_db(tmp_path_factory):
dir = tmp_path_factory.mktemp("wn_data_empty")
with pytest.MonkeyPatch.context() as m:
m.setattr(wn.config, "data_directory", dir)
yield
# We want to build these DBs once per session, but connections
# are created once for every test.
@pytest.fixture(scope="session")
def mini_db_dir(datadir, tmp_path_factory):
dir = tmp_path_factory.mktemp("wn_data_mini")
with pytest.MonkeyPatch.context() as m:
m.setattr(wn.config, "data_directory", dir)
wn.add(datadir / "mini-lmf-1.0.xml")
wn.add(datadir / "mini-ili.tsv")
wn._db.clear_connections()
return Path(dir)
@pytest.fixture
def mini_lmf_compressed(datadir, tmp_path):
data = (datadir / "mini-lmf-1.0.xml").read_bytes()
path = tmp_path / "temp.xml.xz"
with lzma.open(path, "w") as f:
f.write(data)
return Path(path)
@pytest.fixture(scope="session")
def mini_db_1_1_dir(datadir, tmp_path_factory):
dir = tmp_path_factory.mktemp("wn_data_mini_1_1")
with pytest.MonkeyPatch.context() as m:
m.setattr(wn.config, "data_directory", dir)
wn.add(datadir / "mini-lmf-1.0.xml")
wn.add(datadir / "mini-lmf-1.1.xml")
wn._db.clear_connections()
return Path(dir)
@pytest.fixture(scope="session")
def mini_db_1_4_dir(datadir, tmp_path_factory):
dir = tmp_path_factory.mktemp("wn_data_mini_1_4")
with pytest.MonkeyPatch.context() as m:
m.setattr(wn.config, "data_directory", dir)
wn.add(datadir / "mini-lmf-1.0.xml")
wn.add(datadir / "mini-lmf-1.4.xml")
wn._db.clear_connections()
return Path(dir)
@pytest.fixture
def mini_db(monkeypatch, mini_db_dir):
with monkeypatch.context() as m:
m.setattr(wn.config, "data_directory", mini_db_dir)
yield
wn._db.clear_connections()
@pytest.fixture
def mini_db_1_1(monkeypatch, mini_db_1_1_dir):
with monkeypatch.context() as m:
m.setattr(wn.config, "data_directory", mini_db_1_1_dir)
yield
wn._db.clear_connections()
@pytest.fixture
def mini_db_1_4(monkeypatch, mini_db_1_4_dir):
with monkeypatch.context() as m:
m.setattr(wn.config, "data_directory", mini_db_1_4_dir)
yield
wn._db.clear_connections()
|