Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion imagedephi/modify_dates_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ svs:
action: keep
CalibrationAverageRed:
action: keep
Calibration Point Source:
action: keep
ScannerType:
action: delete
SessionMode:
Expand All @@ -824,7 +826,7 @@ dicom:
action: delete
default:
action: keep
delete_custom_metadata: true
custom_metadata_action: delete
metadata:
AccessionNumber:
action: empty
Expand Down
34 changes: 34 additions & 0 deletions tests/test_profile_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import importlib.resources
from typing import Any

import yaml


def _load_profile(file_name: str) -> dict:
with (importlib.resources.files("imagedephi") / file_name).open() as stream:
return yaml.safe_load(stream)


def _profile_differences(base: Any, other: Any, path: str = "") -> list[str]:
"""List places where the modify dates profile deviates from the base profile."""
if isinstance(base, dict) and isinstance(other, dict):
differences = [f"{path}/{key}: only in base rules" for key in base.keys() - other.keys()]
differences += [
f"{path}/{key}: only in modify dates rules" for key in other.keys() - base.keys()
]
for key in base.keys() & other.keys():
differences += _profile_differences(base[key], other[key], f"{path}/{key}")
return differences
if base == other or (path.endswith("/action") and other == "modify_date"):
return []
return [f"{path}: {base!r} != {other!r}"]


def test_modify_dates_profile_matches_base_profile():
base = _load_profile("base_rules.yaml")
modify_dates = _load_profile("modify_dates_rules.yaml")
for key in ("name", "description"):
base.pop(key)
modify_dates.pop(key)

assert sorted(_profile_differences(base, modify_dates)) == []
Loading