|
a |
|
b/tests/unit/test_example_data.py |
|
|
1 |
from pathlib import Path |
|
|
2 |
|
|
|
3 |
import pytest |
|
|
4 |
|
|
|
5 |
import ehrql |
|
|
6 |
from ehrql.query_engines.local_file import LocalFileQueryEngine |
|
|
7 |
from ehrql.query_language import BaseFrame |
|
|
8 |
from ehrql.tables import core |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
# Example CSV files are given for all core tables |
|
|
12 |
EXAMPLE_TABLES = [getattr(core, table) for table in core.__all__] |
|
|
13 |
|
|
|
14 |
EXAMPLE_DATA_DIR = Path(ehrql.__file__).parent / "example-data" |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
@pytest.mark.parametrize( |
|
|
18 |
"ql_table", |
|
|
19 |
EXAMPLE_TABLES, |
|
|
20 |
ids=lambda t: f"{t.__module__}.{t.__class__.__qualname__}", |
|
|
21 |
) |
|
|
22 |
def test_populate_database_using_example_data(ql_table: BaseFrame): |
|
|
23 |
# The engine populates the database with the example data and validates the column |
|
|
24 |
# specs in the process |
|
|
25 |
engine = LocalFileQueryEngine(EXAMPLE_DATA_DIR) |
|
|
26 |
engine.populate_database([ql_table._qm_node], allow_missing_columns=False) |