Skip to content

Commit 2862c9a

Browse files
committed
RF: Gather/use list of all dicom files to avoid calling wrapper_from_file at module level
I think it is safer to avoid 3rd party library calls at the module import time since if they are buggy it would be too loud of kaboom. Also it adds CPU time at import time even if not used later on. So replaced with defining a list of all DICOMs and then just using that function directly from filename. This also would run it against more DICOMs as this time we would glob recursively.
1 parent 9afeae9 commit 2862c9a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

heudiconv/tests/test_dicoms.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
parse_private_csa_header,
2222
)
2323

24-
from .utils import TESTS_DATA_PATH
24+
from .utils import TEST_DICOM_PATHS, TESTS_DATA_PATH
2525

2626
# Public: Private DICOM tags
2727
DICOM_FIELDS_TO_TEST = {"ProtocolName": "tProtocolName"}
@@ -180,21 +180,13 @@ def test_get_datetime_from_dcm_wo_dt() -> None:
180180
assert get_datetime_from_dcm(XA30_enhanced_dcm) is None
181181

182182

183-
dicom_test_data = [
184-
(dw.wrapper_from_file(d_file), [d_file], op.basename(d_file))
185-
for d_file in glob(op.join(TESTS_DATA_PATH, "*.dcm"))
186-
]
187-
188-
189-
@pytest.mark.parametrize("mw,series_files,series_id", dicom_test_data)
183+
@pytest.mark.parametrize("dcmfile", TEST_DICOM_PATHS)
190184
def test_create_seqinfo(
191-
mw: dw.Wrapper,
192-
series_files: list[str],
193-
series_id: str,
185+
dcmfile,
194186
) -> None:
195-
seqinfo = create_seqinfo(mw, series_files, series_id)
196-
assert seqinfo.sequence_name != ""
197-
pass
187+
mw = dw.wrapper_from_file(dcmfile)
188+
seqinfo = create_seqinfo(mw, [dcmfile], op.basename(dcmfile))
189+
assert seqinfo.sequence_name
198190

199191

200192
def test_get_reproducible_int() -> None:

heudiconv/tests/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from glob import glob
34
import logging
45
import os.path as op
56
from pathlib import Path
@@ -9,6 +10,14 @@
910

1011
HEURISTICS_PATH = op.join(heudiconv.heuristics.__path__[0])
1112
TESTS_DATA_PATH = op.join(op.dirname(__file__), "data")
13+
# Do relative to curdir to shorten in a typical application,
14+
# and side-effect test that tests do not change curdir.
15+
TEST_DICOM_PATHS = [
16+
op.relpath(x)
17+
for x in glob(op.join(TESTS_DATA_PATH, "**/*.dcm"), recursive=True)
18+
# exclude PhoenixDocuments
19+
if "PhoenixDocument" not in x
20+
]
1221

1322
lgr = logging.getLogger(__name__)
1423

0 commit comments

Comments
 (0)