Skip to content

Commit 854b817

Browse files
committed
RF: Move dicom import into test function
Include a comment about why the tag might be missing.
1 parent 61b198d commit 854b817

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

nibabel/nicom/csareader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def get_csa_header(dcm_data, csa_type='image'):
6666
try:
6767
tag = dcm_data[(0x29, element_no)]
6868
except KeyError:
69+
# The element could be missing due to anonymization
6970
return None
7071
return read(tag.value)
7172

nibabel/nicom/tests/test_csareader.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
from .test_dicomwrappers import (have_dicom, dicom_test,
1616
IO_DATA_PATH, DATA, DATA_FILE)
17-
if have_dicom:
18-
from .test_dicomwrappers import pydicom
1917

2018
CSA2_B0 = open(pjoin(IO_DATA_PATH, 'csa2_b0.bin'), 'rb').read()
2119
CSA2_B1000 = open(pjoin(IO_DATA_PATH, 'csa2_b1000.bin'), 'rb').read()
@@ -138,8 +136,12 @@ def test_missing_csa_elem():
138136
# Test that we get None instead of raising an Exception when the file has
139137
# the PrivateCreator element for the CSA dict but not the element with the
140138
# actual CSA header (perhaps due to anonymization)
139+
try:
140+
from dicom.tag import Tag
141+
except ImportError:
142+
from pydicom.tag import Tag
141143
dcm = deepcopy(DATA)
142-
csa_tag = pydicom.tag.Tag(0x29, 0x1010)
144+
csa_tag = Tag(0x29, 0x1010)
143145
del dcm[csa_tag]
144146
hdr = csa.get_csa_header(dcm, 'image')
145147
assert_equal(hdr, None)

0 commit comments

Comments
 (0)