test_operations.py 946 Bytes
Newer Older
1
import os
2
3
import shutil
import tempfile
4
5
6
from pathlib import Path
from typing import Iterator

7
from pytest import fixture
8
9
10
11
12
13
14
15
16
17
18
19
20

from repo_management import models, operations

from .fixtures import create_db_file


@fixture(scope="function")
def create_gz_db_file() -> Iterator[Path]:
    db_file = create_db_file()
    yield db_file
    os.remove(db_file)


21
22
23
24
25
26
27
@fixture(scope="function")
def create_dir_path() -> Iterator[Path]:
    temp_dir = tempfile.mkdtemp()
    yield Path(temp_dir)
    shutil.rmtree(temp_dir)


28
29
30
31
def test_db_file_as_models(create_gz_db_file: Path) -> None:
    for (name, model) in operations.db_file_as_models(db_path=create_gz_db_file):
        assert isinstance(name, str)
        assert isinstance(model, models.OutputPackageBase)
32
33
34
35
36
37
38


def test_dump_db_to_json_files(
    create_gz_db_file: Path,
    create_dir_path: Path,
) -> None:
    operations.dump_db_to_json_files(input_path=create_gz_db_file, output_path=create_dir_path)