Mercurial > hg > orthanc-tests
comparison Plugins/WSI/Run.py @ 253:74c693e093ce
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Aug 2019 17:44:25 +0200 |
parents | 01db33301c3d |
children | 943166deebcb |
comparison
equal
deleted
inserted
replaced
252:01db33301c3d | 253:74c693e093ce |
---|---|
90 ORTHANC = DefineOrthanc(server = args.server, | 90 ORTHANC = DefineOrthanc(server = args.server, |
91 username = args.username, | 91 username = args.username, |
92 password = args.password, | 92 password = args.password, |
93 restPort = args.rest) | 93 restPort = args.rest) |
94 | 94 |
95 def CallDicomizer(suffix): | 95 def CallCommand(command): |
96 prefix = [] | 96 prefix = [] |
97 if args.valgrind: | 97 if args.valgrind: |
98 prefix = [ 'valgrind' ] | 98 prefix = [ 'valgrind' ] |
99 | 99 |
100 log = subprocess.check_output(prefix + [ args.dicomizer, | 100 log = subprocess.check_output(prefix + command, |
101 '--username=%s' % args.username, | |
102 '--password=%s' % args.password ] + suffix, | |
103 stderr=subprocess.STDOUT) | 101 stderr=subprocess.STDOUT) |
104 | 102 |
105 # If using valgrind, only print the lines from the log starting | 103 # If using valgrind, only print the lines from the log starting |
106 # with '==' (they contain the report from valgrind) | 104 # with '==' (they contain the report from valgrind) |
107 if args.valgrind: | 105 if args.valgrind: |
108 print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines()))) | 106 print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines()))) |
107 | |
108 | |
109 def CallDicomizer(suffix): | |
110 CallCommand([ args.dicomizer, | |
111 '--username=%s' % args.username, | |
112 '--password=%s' % args.password ] + suffix) | |
113 | |
114 | |
115 def CallDicomToTiff(suffix): | |
116 CallCommand([ args.to_tiff ] + suffix) | |
117 | |
118 | |
119 def CallTiffInfoOnSeries(series): | |
120 with tempfile.NamedTemporaryFile(delete = False) as temp: | |
121 temp.close() | |
122 CallDicomToTiff([ series, temp.name ]) | |
123 tiff = subprocess.check_output([ 'tiffinfo', temp.name ]) | |
124 os.unlink(temp.name) | |
125 | |
126 return tiff | |
109 | 127 |
110 | 128 |
111 class Orthanc(unittest.TestCase): | 129 class Orthanc(unittest.TestCase): |
112 def setUp(self): | 130 def setUp(self): |
113 if (sys.version_info >= (3, 0)): | 131 if (sys.version_info >= (3, 0)): |
145 self.assertEqual(512, pyramid['TileHeight']) | 163 self.assertEqual(512, pyramid['TileHeight']) |
146 self.assertEqual(512, pyramid['TotalWidth']) | 164 self.assertEqual(512, pyramid['TotalWidth']) |
147 self.assertEqual(512, pyramid['TotalHeight']) | 165 self.assertEqual(512, pyramid['TotalHeight']) |
148 self.assertEqual(1, pyramid['TilesCount'][0][0]) | 166 self.assertEqual(1, pyramid['TilesCount'][0][0]) |
149 self.assertEqual(1, pyramid['TilesCount'][0][1]) | 167 self.assertEqual(1, pyramid['TilesCount'][0][1]) |
168 | |
169 tiff = CallTiffInfoOnSeries(s[0]) | |
170 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
171 self.assertEqual(1, len(p)) | |
172 self.assertTrue('YCbCr' in p[0]) | |
150 | 173 |
151 | 174 |
152 def test_grayscale_pyramid(self): | 175 def test_grayscale_pyramid(self): |
153 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ]) | 176 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ]) |
154 | 177 |
191 self.assertEqual(4, pyramid['TilesCount'][1][1]) | 214 self.assertEqual(4, pyramid['TilesCount'][1][1]) |
192 self.assertEqual(2, pyramid['TilesCount'][2][0]) | 215 self.assertEqual(2, pyramid['TilesCount'][2][0]) |
193 self.assertEqual(2, pyramid['TilesCount'][2][1]) | 216 self.assertEqual(2, pyramid['TilesCount'][2][1]) |
194 self.assertEqual(1, pyramid['TilesCount'][3][0]) | 217 self.assertEqual(1, pyramid['TilesCount'][3][0]) |
195 self.assertEqual(1, pyramid['TilesCount'][3][1]) | 218 self.assertEqual(1, pyramid['TilesCount'][3][1]) |
219 | |
220 tiff = CallTiffInfoOnSeries(s[0]) | |
221 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
222 self.assertEqual(4, len(p)) | |
223 for j in range(4): | |
224 self.assertTrue('min-is-black' in p[j]) | |
225 | |
226 | |
227 def test_import_tiff_grayscale(self): | |
228 CallDicomizer([ GetDatabasePath('WSI/LenaGrayscaleJpeg.tiff') ]) | |
229 | |
230 s = DoGet(ORTHANC, '/series') | |
231 self.assertEqual(1, len(s)) | |
232 | |
233 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
234 self.assertEqual(4, len(pyramid['Resolutions'])) | |
235 | |
236 tiff = CallTiffInfoOnSeries(s[0]) | |
237 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
238 self.assertEqual(4, len(p)) | |
239 for j in range(4): | |
240 self.assertTrue('min-is-black' in p[j]) | |
241 | |
242 | |
243 def test_import_tiff_ycbcr(self): | |
244 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegYCbCr.tiff') ]) | |
245 | |
246 s = DoGet(ORTHANC, '/series') | |
247 self.assertEqual(1, len(s)) | |
248 | |
249 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
250 self.assertEqual(4, len(pyramid['Resolutions'])) | |
251 | |
252 tiff = CallTiffInfoOnSeries(s[0]) | |
253 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
254 self.assertEqual(4, len(p)) | |
255 for j in range(4): | |
256 self.assertTrue('YCbCr' in p[j]) | |
257 | |
258 | |
259 def test_import_tiff_rgb(self): | |
260 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegRGB.tiff') ]) | |
261 | |
262 s = DoGet(ORTHANC, '/series') | |
263 self.assertEqual(1, len(s)) | |
264 | |
265 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
266 self.assertEqual(4, len(pyramid['Resolutions'])) | |
267 | |
268 tiff = CallTiffInfoOnSeries(s[0]) | |
269 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
270 self.assertEqual(4, len(p)) | |
271 for j in range(4): | |
272 self.assertTrue('RGB' in p[j]) | |
273 | |
196 | 274 |
197 try: | 275 try: |
198 print('\nStarting the tests...') | 276 print('\nStarting the tests...') |
199 unittest.main(argv = [ sys.argv[0] ] + args.options) | 277 unittest.main(argv = [ sys.argv[0] ] + args.options) |
200 | 278 |