Skip to content

Commit

Permalink
Add some tests of the validate_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pipliggins committed Aug 1, 2024
1 parent ca283d3 commit 6258eb4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Binary file added tests/ingestion_output_errors/encounter.parquet
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/ingestion_output_errors/fhirflat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[metadata]
N = NA
generator = "fhirflat/0.1.0"
checksum = "437a5f50450c7671084451fc83d2c049239bcc8686cdd663823589ec689d872a"
checksum_file = "sha256sums.txt"
1 change: 1 addition & 0 deletions tests/ingestion_output_errors/sha256sums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8980474796eea6a656ae2d6cf5c6d31f290d97e2bbe39eaa0469d2ebed8e3df1 encounter.parquet
55 changes: 55 additions & 0 deletions tests/test_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
checksum,
main,
validate,
validate_cli,
)
from fhirflat.resources.encounter import Encounter
from fhirflat.resources.observation import Observation
Expand Down Expand Up @@ -938,6 +939,45 @@ def test_convert_data_to_flat_wrong_mapping_type_error():
)


def test_convert_data_to_flat_no_validation_warning():
mappings = {
Encounter: "tests/dummy_data/encounter_dummy_mapping.csv",
}
resource_types = {"Encounter": "one-to-one"}

with pytest.warns(
UserWarning, match="Validation of the FHIRflat files has been disabled"
):
convert_data_to_flat(
"tests/dummy_data/combined_dummy_data.csv",
folder_name="tests/ingestion_output",
date_format="%Y-%m-%d",
timezone="Brazil/East",
mapping_files_types=(mappings, resource_types),
validate=False,
)
shutil.rmtree("tests/ingestion_output")


# TODO: write a working version of this (needs data like the private ones)
# def test_convert_data_to_flat_no_validation_invalid_file_warning():
# mappings = {
# Encounter: "tests/dummy_data/encounter_dummy_mapping.csv",
# }
# resource_types = {"Encounter": "one-to-one"}

# with pytest.warns(UserWarning, match="This is likely due to a validation error"):
# convert_data_to_flat(
# "tests/dummy_data/combined_dummy_data_error.csv",
# folder_name="tests/ingestion_output_errors",
# date_format="%Y-%m-%d",
# timezone="Brazil/East",
# mapping_files_types=(mappings, resource_types),
# validate=False,
# )
# shutil.rmtree("tests/ingestion_output_errors")


def test_generate_metadata():
meta = generate_metadata("tests/bundle")
assert meta[0]["checksum"] == METADATA_CHECKSUM
Expand Down Expand Up @@ -1021,6 +1061,8 @@ def test_convert_data_to_flat_local_mapping_zipped():
os.remove("tests/ingestion_output.zip")


# This don't run intermittantly - because of the "#NAME" error i get with the googele sheets
# Turns out this is an issue with custom functions in Google Sheets, not a Python thing.
def test_main(capsys, monkeypatch):
# Simulate command line arguments
monkeypatch.setattr(
Expand All @@ -1042,6 +1084,19 @@ def test_main(capsys, monkeypatch):
shutil.rmtree("fhirflat_output")


def test_validate_cli(capsys, monkeypatch):
# Simulate command line arguments
monkeypatch.setattr(
"sys.argv",
["ingest.py", "tests/data/valid_flat_bundle"],
)
validate_cli()
captured = capsys.readouterr()
assert "encounter.parquet is valid" in captured.out
assert "condition.parquet is valid" in captured.out
assert "validation errors" not in captured.out


def test_validate_fhirflat_single_resource_errors():
df = pd.DataFrame(
{
Expand Down

0 comments on commit 6258eb4

Please sign in to comment.