-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest_all.py
157 lines (115 loc) · 4.97 KB
/
test_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from src.DicomRTTool.ReaderWriter import DicomReaderWriter, os, sitk, np
import zipfile
import pytest
"""
First, check to see if .zip files have been unzipped
"""
base = '.'
i = 0
while 'AnonDICOM.zip' not in os.listdir(base):
i += 1
base = os.path.join(base, '..')
if i > 3:
break
if not os.path.exists(os.path.join(base, 'AnonDICOM')):
with zipfile.ZipFile(os.path.join(base, "AnonDICOM.zip"), 'r') as zip_ref:
zip_ref.extractall(base)
@pytest.fixture
def path():
base = '.'
i = 0
while 'AnonDICOM' not in os.listdir(base):
i += 1
base = os.path.join(base, '..')
if i > 3:
break
return os.path.join(base, 'AnonDICOM')
@pytest.fixture
def base_mask(path):
return sitk.ReadImage(os.path.join(path, 'Mask.nii.gz'))
@pytest.fixture
def base_mask007(path):
return sitk.ReadImage(os.path.join(path, 'Mask_007.nii.gz'))
@pytest.fixture
def base_mask009(path):
return sitk.ReadImage(os.path.join(path, 'Mask_009.nii.gz'))
@pytest.fixture
def base_image(path):
return sitk.ReadImage(os.path.join(path, 'Image.nii.gz'))
@pytest.fixture
def main_reader(path):
reader = DicomReaderWriter(description='Examples', Contour_Names=['spinalcord', 'body'],
arg_max=True, verbose=True)
reader.walk_through_folders(path, thread_count=1) # For pytest to work, thread_count MUST be 1
reader.set_index(reader.indexes_with_contours[0])
reader.get_mask()
return reader
@pytest.fixture
def main_reader007(main_reader):
main_reader.set_contour_names_and_associations(contour_names=['brainstem', 'dose 1200[cgy]', 'dose 500[cgy]'])
main_reader.set_index(main_reader.indexes_with_contours[0])
main_reader.get_images_and_mask()
return main_reader
@pytest.fixture
def main_reader009(main_reader007):
main_reader007.set_index(main_reader007.indexes_with_contours[1])
main_reader007.get_images_and_mask()
return main_reader007
class TestMaskCTChecker(object):
@pytest.fixture(autouse=True)
def setup(self, main_reader, base_mask):
self.reader = main_reader
self.mask = base_mask
def test_performed(self):
assert self.reader.annotation_handle
def test_size(self):
assert self.mask.GetSize() == self.reader.annotation_handle.GetSize()
def test_spacing(self):
assert self.mask.GetSpacing() == self.reader.annotation_handle.GetSpacing()
def test_direction(self):
assert self.mask.GetDirection() == self.reader.annotation_handle.GetDirection()
def test_origin(self):
assert self.mask.GetOrigin() == self.reader.annotation_handle.GetOrigin()
def test_array(self):
assert np.min(sitk.GetArrayFromImage(self.reader.annotation_handle) ==
sitk.GetArrayFromImage(self.mask))
class TestMaskMR007Checker(object):
@pytest.fixture(autouse=True)
def setup(self, main_reader007, base_mask007):
self.reader = main_reader007
self.mask = base_mask007
def test_performed(self):
assert self.reader.annotation_handle
def test_size(self):
assert self.mask.GetSize() == self.reader.annotation_handle.GetSize()
def test_spacing(self):
assert tuple(map(lambda x: isinstance(x, float) and round(x, 6) or x, self.mask.GetSpacing()))\
== self.reader.annotation_handle.GetSpacing()
def test_direction(self):
assert self.mask.GetDirection() == self.reader.annotation_handle.GetDirection()
def test_origin(self):
assert tuple(map(lambda x: isinstance(x, float) and round(x, 3) or x, self.mask.GetOrigin()))\
== self.reader.annotation_handle.GetOrigin()
def test_array(self):
assert np.min(sitk.GetArrayFromImage(self.reader.annotation_handle) ==
sitk.GetArrayFromImage(self.mask))
class TestMaskMR009Checker(object):
@pytest.fixture(autouse=True)
def setup(self, main_reader009, base_mask009):
self.reader = main_reader009
self.mask = base_mask009
def test_performed(self):
assert self.reader.annotation_handle
def test_size(self):
assert self.mask.GetSize() == self.reader.annotation_handle.GetSize()
def test_spacing(self):
assert tuple(map(lambda x: isinstance(x, float) and round(x, 6) or x, self.mask.GetSpacing()))\
== self.reader.annotation_handle.GetSpacing()
def test_direction(self):
assert self.mask.GetDirection() == self.reader.annotation_handle.GetDirection()
def test_origin(self):
assert tuple(map(lambda x: isinstance(x, float) and round(x, 3) or x, self.mask.GetOrigin()))\
== self.reader.annotation_handle.GetOrigin()
def test_array(self):
assert np.min(sitk.GetArrayFromImage(self.reader.annotation_handle) ==
sitk.GetArrayFromImage(self.mask))