Skip to content

Commit

Permalink
fix: multiple dd write now correctly writes all dds
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkranz committed Sep 20, 2023
1 parent 462c53a commit 38d80d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
38 changes: 23 additions & 15 deletions src/healdata_utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,14 @@ def convert_to_vlmd(
"errors": {"csvtemplate": reportcsv, "jsontemplate": reportjson},
})

output_filepath_with_name = output_filepath

if output_filepath:
_write_vlmd(
jsontemplate=dd_json,
csvtemplate=dd_csv,
csvreport=reportcsv,
jsonreport=reportjson,
output_filepath=output_filepath,
output_overwrite=output_overwrite)
else:

packages_with_reports[name] = {
Expand All @@ -304,19 +310,21 @@ def convert_to_vlmd(
}

#
stem = Path(output_filepath).stem
ext = Path(output_filepath).suffix
output_filepath_with_name = Path(output_filepath).parent/(stem+"-"+slugify(name)+ext)

if output_filepath_with_name:
_write_vlmd(
jsontemplate=dd_json,
csvtemplate=dd_csv,
csvreport=reportcsv,
jsonreport=reportjson,
output_filepath=output_filepath_with_name,
output_overwrite=output_overwrite
)

if output_filepath:

stem = Path(output_filepath).stem
ext = Path(output_filepath).suffix
output_filepath_with_name = Path(output_filepath).parent/(stem+"-"+slugify(name)+ext)

_write_vlmd(
jsontemplate=dd_json,
csvtemplate=dd_csv,
csvreport=reportcsv,
jsonreport=reportjson,
output_filepath=output_filepath_with_name,
output_overwrite=output_overwrite
)


return packages_with_reports
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_vlmd_extract_all_params(
# currently json and csv are produced automatically
# so should be both a csv and json file (at least 2 files)
# more than 2 happens in cases of package-like dds formed such as with excel
if len(list(_outdir.glob("*.json"))) > 1 and len(list(_outdir.glob("*.csv"))) > 1:
if isinstance(valid_output_json[inputtype],dict) and isinstance(valid_output_csv[inputtype],dict):
for name in valid_output_json[inputtype]:
_valid_output_json = json.loads(valid_output_json[inputtype][name].read_text())
_valid_output_csv = valid_output_csv[inputtype][name].read_text().split("\n")
Expand Down

0 comments on commit 38d80d8

Please sign in to comment.