Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Sep 24, 2024
1 parent 2d74329 commit 8b727f0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions cumulus_library/actions/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def run_statistics_builders(

if (target_table,) in existing_stats and not config.stats_build:
continue
print(config_type)
if config_type == "psm":
builder = psm_builder.PsmBuilder(
toml_config_path=toml_path,
Expand Down
4 changes: 2 additions & 2 deletions cumulus_library/builders/valueset/vsac.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def download_oid_data(
api_key = config.umls_key
force_upload = config.force_upload
if not path:
path = pathlib.Path(__file__).parent.parent / "data"
path = pathlib.Path(__file__).parent.parent / "data" # pragma: no cover
path.mkdir(exist_ok=True, parents=True)
if not (force_upload) and (path / f"{steward}.parquet").exists():
print(f"{steward} data present at {path}, skipping download.")
Expand Down Expand Up @@ -78,4 +78,4 @@ def main(cli_args=None):


if __name__ == "__main__":
main() # pragma: no-cover
main() # pragma: no cover
30 changes: 22 additions & 8 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import shutil
import zipfile
from contextlib import nullcontext as does_not_raise
from pathlib import Path
from unittest import mock

import pandas
Expand Down Expand Up @@ -112,7 +111,6 @@ def test_clean_throws_error_on_missing_params(mock_db_config):
[
("./tests/test_data/study_valid/", False),
("./tests/test_data/psm/", True),
("./tests/test_data/valueset/", True),
],
)
def test_run_protected_table_builder(mock_db_config, study_path, stats):
Expand Down Expand Up @@ -287,11 +285,11 @@ def test_build_study(mock_db_config, study_path, verbose, expects, raises):
),
],
)
def test_run_statistics_builders(
def test_run_psm_statistics_builders(
tmp_path, mock_db_stats_config, study_path, stats, previous, expects, raises
):
with raises:
manifest = study_manifest.StudyManifest(study_path, data_path=tmp_path)
manifest = study_manifest.StudyManifest(pathlib.Path(study_path), data_path=tmp_path)
config = base_utils.StudyConfig(
db=mock_db_stats_config.db,
schema=mock_db_stats_config.schema,
Expand Down Expand Up @@ -322,9 +320,25 @@ def test_run_statistics_builders(
assert expects in tables


@mock.patch("cumulus_library.builders.valueset_builder.ValuesetBuilder")
def test_invoke_valueset_builder(mock_builder, mock_db_config):
manifest = study_manifest.StudyManifest(
pathlib.Path(__file__).parent.parent / "cumulus_library/studies/core"
)
config = base_utils.StudyConfig(
db=mock_db_config.db,
schema=mock_db_config.schema,
)
builder.run_protected_table_builder(
config=config,
manifest=manifest,
)
assert mock_builder.is_called()


def test_export_study(tmp_path, mock_db_core_config):
manifest = study_manifest.StudyManifest(
f"{Path(__file__).parent.parent}/cumulus_library/studies/core",
f"{pathlib.Path(__file__).parent.parent}/cumulus_library/studies/core",
data_path=f"{tmp_path}/export",
)
exporter.export_study(
Expand All @@ -334,7 +348,7 @@ def test_export_study(tmp_path, mock_db_core_config):
archive=False,
chunksize=20,
)
for file in Path(f"{tmp_path}/export").glob("*.*"):
for file in pathlib.Path(f"{tmp_path}/export").glob("*.*"):
assert file in manifest.get_export_table_list()


Expand Down Expand Up @@ -465,7 +479,7 @@ def test_upload_data(user, id_token, status, preview, login_error, raises):
def test_generate_sql(mock_db_config, tmp_path, study, external):
with does_not_raise():
shutil.copytree(
f"{Path(__file__).resolve().parents[0]}/test_data/{study}",
f"{pathlib.Path(__file__).resolve().parents[0]}/test_data/{study}",
f"{tmp_path}/{study}/",
)
manifest = study_manifest.StudyManifest(study_path=pathlib.Path(f"{tmp_path}/{study}/"))
Expand All @@ -488,7 +502,7 @@ def test_generate_sql(mock_db_config, tmp_path, study, external):
def test_generate_md(mock_db_config, tmp_path):
with does_not_raise():
shutil.copytree(
f"{Path(__file__).resolve().parents[0]}/test_data/study_python_valid",
f"{pathlib.Path(__file__).resolve().parents[0]}/test_data/study_python_valid",
f"{tmp_path}/study_python_valid/",
)
manifest = study_manifest.StudyManifest(
Expand Down
4 changes: 4 additions & 0 deletions tests/valueset/rules_file.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TTY1 RELA TTY2 INCLUDE
BN reformulated_to BN Yes
BN reformulation_of BN No
BN tradename_of IN Keyword
10 changes: 5 additions & 5 deletions tests/valueset/test_static_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.mark.parametrize(
"filtered,ignore_header,prefix_str,keyword_path,mapping,expected",
"filtered,ignore_header,prefix_str,rules_file,mapping,expected",
[
(
None,
Expand Down Expand Up @@ -37,7 +37,7 @@
None,
True,
"",
"keywords.tsv",
"rules_file.tsv",
None,
{
"headers": ["foo", "bar"],
Expand All @@ -62,7 +62,7 @@
],
)
def test_static_tables(
tmp_path, mock_db_config, filtered, ignore_header, prefix_str, keyword_path, mapping, expected
tmp_path, mock_db_config, filtered, ignore_header, prefix_str, rules_file, mapping, expected
):
mock_db_config.options = {"steward": "acep"}
test_path = pathlib.Path(__file__).parent.parent / "test_data/valueset/"
Expand All @@ -74,8 +74,8 @@ def test_static_tables(
if prefix_str:
valueset_config.table_prefix = prefix_str
prefix_str += "_"
if keyword_path:
valueset_config.keyword_path = keyword_path
if rules_file:
valueset_config.rules_file = rules_file
builder = static_builder.StaticBuilder()
filtered = tmp_path / filtered if filtered else None
builder.get_table_configs = lambda prefix: [
Expand Down

0 comments on commit 8b727f0

Please sign in to comment.