Skip to content

Commit a7c5917

Browse files
committed
Add tests for test_should_exclude_manufacturer
1 parent 6b707cb commit a7c5917

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pixl_dcmd/src/pixl_dcmd/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def _should_exclude_manufacturer(dataset: Dataset, cfg: PixlConfig) -> bool:
115115
manufacturer = dataset.get("Manufacturer")
116116
if manufacturer is None:
117117
logger.debug("FILTERING out as manufacturer tag is missing")
118+
return True
118119

119120
should_exclude = not cfg.is_manufacturer_allowed(manufacturer=manufacturer)
120121
if should_exclude:

pixl_dcmd/tests/test_main.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
anonymise_dicom,
4444
_enforce_allowlist,
4545
_should_exclude_series,
46+
_should_exclude_manufacturer,
4647
)
4748
from pytest_pixl.dicom import generate_dicom_dataset
4849
from pytest_pixl.helpers import run_subprocess
@@ -407,7 +408,11 @@ def test_no_pseudo_patient_id_processing(
407408
)
408409

409410

410-
def _make_dicom(series_description, manufacturer, series_number) -> pydicom.Dataset:
411+
def _make_dicom(
412+
series_description="mri_sequence",
413+
manufacturer="Company",
414+
series_number="901",
415+
) -> pydicom.Dataset:
411416
return generate_dicom_dataset(
412417
SeriesDescription=series_description,
413418
Manufacturer=manufacturer,
@@ -438,10 +443,26 @@ def test_should_exclude_series(
438443
config = load_project_config(TEST_PROJECT_SLUG)
439444
ds = _make_dicom(series_description, manufacturer, series_number)
440445
series_number = ds.get("SeriesNumber")
441-
print(f"{series_number=}", type(series_number), str(series_number))
442446
assert _should_exclude_series(ds, config) == expect_exclude
443447

444448

449+
@pytest.mark.parametrize(
450+
("manufacturer", "expect_exclude"),
451+
[
452+
("Company", False),
453+
("DifferentCompany", True),
454+
(None, True),
455+
],
456+
)
457+
def test_should_exclude_manufacturer(manufacturer, expect_exclude):
458+
config = load_project_config(TEST_PROJECT_SLUG)
459+
ds = _make_dicom(manufacturer=manufacturer)
460+
if manufacturer is None:
461+
# the Manufacturer tag is sometimes missing in real data
462+
delattr(ds, "Manufacturer")
463+
assert _should_exclude_manufacturer(ds, config) == expect_exclude
464+
465+
445466
def test_can_nifti_convert_post_anonymisation(
446467
tmp_path,
447468
directory_of_mri_dicoms,

0 commit comments

Comments
 (0)