Skip to content

Commit cc37e63

Browse files
authored
Add Synthea & WDI e2e tests (#416)
Add Synthea and World Development Indicators datasets. `custom_datasets_connection` and `get_test_graph_by_name`fixtures help the addition of new datasets
1 parent 40ddd84 commit cc37e63

21 files changed

+9341
-0
lines changed

tests/conftest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,25 @@ def sample_graph_names(request) -> str:
185185
return request.param
186186

187187

188+
@pytest.fixture(scope="session")
189+
def get_test_graph_by_name() -> graph_fetcher:
190+
"""
191+
Returns a known test graph requested if the graph location was included in test_graph_location.
192+
"""
193+
test_graph_location: dict[str, str] = {
194+
"synthea": "synthea_graph.json",
195+
"world_development_indicators": "world_development_indicators_graph.json",
196+
}
197+
198+
@cache
199+
def impl(name: str) -> GraphMetadata:
200+
file_name: str = test_graph_location[name]
201+
path: str = f"{os.path.dirname(__file__)}/test_metadata/{file_name}"
202+
return pydough.parse_json_metadata_from_file(file_path=path, graph_name=name)
203+
204+
return impl
205+
206+
188207
@pytest.fixture(scope="session")
189208
def get_mysql_defog_graphs() -> graph_fetcher:
190209
"""
@@ -573,6 +592,41 @@ def sqlite_cryptbank_connection() -> DatabaseContext:
573592
return DatabaseContext(DatabaseConnection(connection), DatabaseDialect.SQLITE)
574593

575594

595+
@pytest.fixture(scope="session")
596+
def sqlite_custom_datasets_connection() -> DatabaseContext:
597+
"""
598+
Returns the SQLITE database connection with all the custom datasets attached.
599+
"""
600+
commands: list[str] = [
601+
"cd tests/gen_data",
602+
"rm -fv synthea.db",
603+
"rm -fv world_development_indicators.db",
604+
"sqlite3 synthea.db < init_synthea.sql",
605+
"sqlite3 world_development_indicators.db < init_world_indicators_sqlite.sql",
606+
]
607+
# Get the shell commands required to re-create all the db files
608+
shell_cmd: str = "; ".join(commands)
609+
610+
# Setup the directory to be the main PyDough directory.
611+
base_dir: str = os.path.dirname(os.path.dirname(__file__))
612+
# Setup the world development indicators database.
613+
subprocess.run(shell_cmd, shell=True, check=True)
614+
# Central in-memory connection
615+
connection: sqlite3.Connection = sqlite3.connect(":memory:")
616+
617+
# Dict: schema_name → database file path
618+
dbs: dict[str, str] = {
619+
"synthea": "tests/gen_data/synthea.db",
620+
"wdi": "tests/gen_data/world_development_indicators.db",
621+
}
622+
623+
# Attach them all
624+
for schema, path in dbs.items():
625+
path = os.path.join(base_dir, path)
626+
connection.execute(f"ATTACH DATABASE '{path}' AS {schema}")
627+
return DatabaseContext(DatabaseConnection(connection), DatabaseDialect.SQLITE)
628+
629+
576630
SF_ENVS = ["SF_USERNAME", "SF_PASSWORD", "SF_ACCOUNT"]
577631
"""
578632
Snowflake environment variables required for connection.

tests/gen_data/init_synthea_sqlite.sql

Lines changed: 3564 additions & 0 deletions
Large diffs are not rendered by default.

tests/gen_data/init_world_indicators_sqlite.sql

Lines changed: 2597 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)