Skip to content

Commit

Permalink
test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Feb 9, 2024
1 parent bc25632 commit abd2ba5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cumulus_library/study_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,13 @@ def export_study(
schema_name: str,
data_path: pathlib.Path,
archive: bool,
) -> None:
) -> list:
"""Exports csvs/parquet extracts of tables listed in export_list
:param db: A database backend
:param schema_name: the schema/database to target
:param data_path: the path to the place on disk to save data
:param archive: If true, get all study data and zip with timestamp
:returns: a list of queries, (only for unit tests)
"""
table_list = []
path = pathlib.Path(f"{data_path}/{self.get_study_prefix()}/")
Expand All @@ -692,6 +693,7 @@ def export_study(
table_list.append(row[0])
else:
table_list = self.get_export_table_list()
queries = []
for table in track(
table_list,
description=f"Exporting {self.get_study_prefix()} data...",
Expand All @@ -707,6 +709,7 @@ def export_study(
)
if not archive:
dataframe.to_parquet(f"{path}/{table}.parquet", index=False)
queries.append(queries)
if archive:
file_list = [file for file in path.glob("**/*") if file.is_file()]
timestamp = (
Expand All @@ -723,3 +726,4 @@ def export_study(
f.write(file, file.relative_to(path))
file.unlink()
shutil.rmtree(path)
return queries
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_cli_executes_queries(tmp_path, build_args, export_args, expected_tables

with open(f"{manifest_dir}/manifest.toml", encoding="UTF-8") as file:
config = toml.load(file)
csv_files = glob.glob(f"{tmp_path}/counts/{build_args[2]}/*.csv")
csv_files = glob.glob(f"{tmp_path}/export/{build_args[2]}/*.csv")
for export_table in config["export_config"]["export_list"]:
assert any(export_table in x for x in csv_files)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_study_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,6 @@ def test_export_study(tmp_path, mock_db_core):
f"{Path(__file__).parent.parent}/cumulus_library/studies/core",
data_path=f"{tmp_path}/export",
)
parser.export_study(mock_db_core, f"{tmp_path}/export")
parser.export_study(mock_db_core, None, f"{tmp_path}/export", False)
for file in Path(f"{tmp_path}/export").glob("*.*"):
assert file in parser.get_export_table_list()

0 comments on commit abd2ba5

Please sign in to comment.