From c09b51be40444ef59809b6148184490bd4972004 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sat, 25 Feb 2023 21:41:47 -0600 Subject: add database tests --- tests/conftest.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/conftest.py') diff --git a/tests/conftest.py b/tests/conftest.py index e2d6946..063f4a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ import os import sys import pytest +import shutil from pathlib import Path from typing import Any, Callable from pytest import MonkeyPatch @@ -11,6 +12,7 @@ from logging import Logger, getLogger, DEBUG from pyssg.arg_parser import get_parser from pyssg.custom_logger import setup_logger +from pyssg.database_entry import DatabaseEntry @pytest.fixture(scope='session') @@ -116,3 +118,61 @@ def tmp_dir_structure(tmp_path: Path) -> Path: for ext in ['txt', 'md', 'html']: (d/f'f{i}.{ext}').write_text('sample') return root + + +@pytest.fixture(scope='session') +def tmp_db_e1() -> DatabaseEntry: + return DatabaseEntry(('first.md', + 1671076311.823135, + 0.0, + '778bce781d95730cd1e872a10130e20d', + '-')) + + +@pytest.fixture(scope='session') +def tmp_db_e2() -> DatabaseEntry: + return DatabaseEntry(('a/second.md', + 1671077831.63301, + # 1671078892.892921, + 1677381461.8107588, + #'6092d6471d3a83135293e34ef6012939', + 'a61d0116844b6ebc02db62b4b1bf453d', + 'english,short,update')) + + +@pytest.fixture(scope='function') +def tmp_db(tmp_path: Path, + tmp_db_e1: DatabaseEntry, + tmp_db_e2: DatabaseEntry) -> Path: + root: Path = tmp_path/'db' + db_path: Path = tmp_path/'db/sample_db.psv' + root.mkdir() + e1: str = '|'.join(tmp_db_e1.get_raw_entry()) + e2: str = '|'.join(tmp_db_e2.get_raw_entry()) + db_path.write_text(f'{e1}\n{e2}\n') + return db_path + + +@pytest.fixture(scope='function') +def tmp_db_wrong_col_num(tmp_path: Path) -> Path: + root: Path = tmp_path/'db' + db_path: Path = tmp_path/'db/sample_db_wrong_col_num.psv' + root.mkdir() + # missing tags, could be anything though + db_path.write_text('name|0.0|0.0|cksm\n') + return db_path + + +@pytest.fixture(scope='function') +def tmp_src_dir(tmp_path: Path, + test_dir: str) -> Path: + src: Path = tmp_path/'src' + src_a: Path = src/'a' + src.mkdir() + src_a.mkdir() + src_test: str = f'{test_dir}/io_files/md' + + files: list[str] = ['first.md', 'new.md', 'a/second.md'] + for f in files: + shutil.copy2(f'{src_test}/{f}', f'{str(src)}/{f}') + return src -- cgit v1.2.3-54-g00ecf