File size: 1,013 Bytes
e4f9cbe
c14732f
e4f9cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c14732f
e4f9cbe
 
 
 
 
 
 
 
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
"""Fixtures for dataset tests."""
import os
import pathlib
from typing import Generator, Optional, Type

import pytest
from pytest_mock import MockerFixture

from .data.dataset import Dataset
from .data.dataset_duckdb import DatasetDuckDB
from .data.dataset_test_utils import make_dataset
from .db_manager import set_default_dataset_cls
from .schema import Item, Schema


@pytest.fixture(scope='function', params=[DatasetDuckDB])
def make_test_data(tmp_path: pathlib.Path, mocker: MockerFixture,
                   request: pytest.FixtureRequest) -> Generator:
  """A pytest fixture for creating temporary test datasets."""
  mocker.patch.dict(os.environ, {'LILAC_DATA_PATH': str(tmp_path)})
  dataset_cls: Type[Dataset] = request.param
  set_default_dataset_cls(dataset_cls)

  def _make_test_data(items: list[Item], schema: Optional[Schema] = None) -> Dataset:
    return make_dataset(dataset_cls, tmp_path, items, schema)

  # Return the factory for datasets that test methods can use.
  yield _make_test_data