|
44 | 44 | try:
|
45 | 45 | import dicom
|
46 | 46 | import struct
|
| 47 | + from io import BytesIO |
47 | 48 | except ImportError:
|
48 | 49 | have_dicom = False
|
49 | 50 | else:
|
@@ -1087,29 +1088,37 @@ def test_nifti_dicom_extension():
|
1087 | 1088 | exts_container = hdr.extensions
|
1088 | 1089 |
|
1089 | 1090 | # create a single dicom tag (Patien ID, [0010,0020]) with Explicit VR
|
1090 |
| - dcmbytes = struct.pack('<HH2sH4s',0x10,0x20, |
| 1091 | + dcmbytes_explicit = struct.pack('<HH2sH4s',0x10,0x20, |
1091 | 1092 | 'LO'.encode('utf-8'),4,'NiPy'.encode('utf-8'))
|
1092 |
| - dcmext = Nifti1DicomExtension(2,dcmbytes) |
| 1093 | + dcmext = Nifti1DicomExtension(2,dcmbytes_explicit) |
1093 | 1094 | assert_equal(dcmext.__class__, Nifti1DicomExtension)
|
| 1095 | + assert_equal(dcmext._guess_implicit_VR(),False) |
| 1096 | + assert_equal(dcmext.get_code(),2) |
1094 | 1097 | assert_equal(dcmext.get_content().PatientID, 'NiPy')
|
1095 | 1098 | assert_equal(len(dcmext.get_content().values()), 1)
|
1096 |
| - |
| 1099 | + assert_equal(dcmext._mangle(dcmext.get_content()),dcmbytes_explicit) |
| 1100 | + assert_equal(dcmext.get_sizeondisk() % 16, 0) |
| 1101 | + |
1097 | 1102 | # create a single dicom tag (Patien ID, [0010,0020]) with Implicit VR
|
1098 |
| - dcmbytes = struct.pack('<HHL4s',0x10,0x20,4,'NiPy'.encode('utf-8')) |
1099 |
| - dcmext = Nifti1DicomExtension(2,dcmbytes) |
| 1103 | + dcmbytes_implicit = struct.pack('<HHL4s',0x10,0x20,4,'NiPy'.encode('utf-8')) |
| 1104 | + dcmext = Nifti1DicomExtension(2,dcmbytes_implicit) |
| 1105 | + assert_equal(dcmext._guess_implicit_VR(),True) |
| 1106 | + assert_equal(dcmext.get_code(),2) |
1100 | 1107 | assert_equal(dcmext.get_content().PatientID, 'NiPy')
|
1101 | 1108 | assert_equal(len(dcmext.get_content().values()), 1)
|
1102 |
| - assert_equal(dcmext.get_sizeondisk(), len(dcmbytes)) |
1103 |
| - assert_equal(dcmext._mangle(),dcmbytes) |
| 1109 | + assert_equal(dcmext._mangle(dcmext.get_content()),dcmbytes_implicit) |
| 1110 | + assert_equal(dcmext.get_sizeondisk() % 16, 0) |
1104 | 1111 |
|
1105 | 1112 | # dicom extension access from nifti extensions
|
1106 | 1113 | assert_equal(exts_container.count('dicom'),0)
|
1107 | 1114 | exts_container.append(dcmext)
|
1108 | 1115 | assert_equal(exts_container.count('dicom'), 1)
|
1109 | 1116 | assert_equal(exts_container.get_codes(), [6, 6, 2])
|
1110 |
| - assert_equal(dcmext.get_sizeondisk(), len(dcmbytes)) |
1111 |
| - assert_equal(dcmext._mangle(),dcmbytes) |
1112 |
| - # assert_equal((exts_container.get_sizeondisk()) % 16, 0) |
| 1117 | + assert_equal(dcmext._mangle(dcmext.get_content()),dcmbytes_implicit) |
| 1118 | + assert_equal(dcmext.get_sizeondisk() % 16, 0) |
| 1119 | + |
| 1120 | + raw_io = BytesIO() |
| 1121 | + dcmext.write_to(raw_io,False) |
1113 | 1122 |
|
1114 | 1123 | class TestNifti1General(object):
|
1115 | 1124 | """ Test class to test nifti1 in general
|
|
0 commit comments