comparison Plugins/WSI/Run.py @ 251:16a5e79accff

testing WSI DICOM-izer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Aug 2019 16:04:41 +0200
parents
children 01db33301c3d
comparison
equal deleted inserted replaced
250:4831008d1500 251:16a5e79accff
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4
5 # Orthanc - A Lightweight, RESTful DICOM Store
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7 # Department, University Hospital of Liege, Belgium
8 # Copyright (C) 2017-2019 Osimis S.A., Belgium
9 #
10 # This program is free software: you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation, either version 3 of the
13 # License, or (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23
24 import argparse
25 import os
26 import pprint
27 import re
28 import subprocess
29 import sys
30 import tempfile
31 import unittest
32 from shutil import copyfile
33
34 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
35 from Toolbox import *
36
37
38 ##
39 ## Parse the command-line arguments
40 ##
41
42 parser = argparse.ArgumentParser(description = 'Run the integration tests for the WSI Dicomizer.')
43
44 parser.add_argument('--server',
45 default = 'localhost',
46 help = 'Address of the Orthanc server to test')
47 parser.add_argument('--rest',
48 type = int,
49 default = 8042,
50 help = 'Port to the REST API')
51 parser.add_argument('--username',
52 default = 'alice',
53 help = 'Username to the REST API')
54 parser.add_argument('--password',
55 default = 'orthanctest',
56 help = 'Password to the REST API')
57 parser.add_argument('--dicomizer',
58 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomizer',
59 help = 'Password to the REST API')
60 parser.add_argument('--to-tiff',
61 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomToTiff',
62 help = 'Password to the REST API')
63 parser.add_argument('--force', help = 'Do not warn the user',
64 action = 'store_true')
65 parser.add_argument('options', metavar = 'N', nargs = '*',
66 help='Arguments to Python unittest')
67
68 args = parser.parse_args()
69
70 if not args.force:
71 print("""
72 WARNING: This test will remove all the content of your
73 Orthanc instance running on %s!
74
75 Are you sure ["yes" to go on]?""" % args.server)
76
77 if sys.stdin.readline().strip() != 'yes':
78 print('Aborting...')
79 exit(0)
80
81
82
83
84 ##
85 ## The tests
86 ##
87
88 ORTHANC = DefineOrthanc(server = args.server,
89 username = args.username,
90 password = args.password,
91 restPort = args.rest)
92
93 def CallDicomizer(p):
94 subprocess.check_output([ args.dicomizer,
95 '--username=%s' % args.username,
96 '--password=%s' % args.password ] + p,
97 stderr=subprocess.STDOUT)
98
99
100 class Orthanc(unittest.TestCase):
101 def setUp(self):
102 if (sys.version_info >= (3, 0)):
103 # Remove annoying warnings about unclosed socket in Python 3
104 import warnings
105 warnings.simplefilter("ignore", ResourceWarning)
106
107 DropOrthanc(ORTHANC)
108
109
110 def test_single(self):
111 CallDicomizer([ GetDatabasePath('Lena.jpg') ])
112
113 i = DoGet(ORTHANC, '/instances')
114 self.assertEqual(1, len(i))
115
116 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[0])
117 self.assertEqual(1, int(tags['NumberOfFrames']))
118 self.assertEqual(512, int(tags['Columns']))
119 self.assertEqual(512, int(tags['Rows']))
120 self.assertEqual('YBR_FULL_422', tags['PhotometricInterpretation'])
121
122 s = DoGet(ORTHANC, '/series')
123 self.assertEqual(1, len(s))
124
125 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
126 self.assertEqual(s[0], pyramid['ID'])
127 self.assertEqual(1, len(pyramid['Resolutions']))
128 self.assertEqual(1, len(pyramid['Sizes']))
129 self.assertEqual(1, len(pyramid['TilesCount']))
130 self.assertEqual(1, pyramid['Resolutions'][0])
131 self.assertEqual(512, pyramid['Sizes'][0][0])
132 self.assertEqual(512, pyramid['Sizes'][0][1])
133 self.assertEqual(512, pyramid['TileWidth'])
134 self.assertEqual(512, pyramid['TileHeight'])
135 self.assertEqual(512, pyramid['TotalWidth'])
136 self.assertEqual(512, pyramid['TotalHeight'])
137 self.assertEqual(1, pyramid['TilesCount'][0][0])
138 self.assertEqual(1, pyramid['TilesCount'][0][1])
139
140
141 def test_grayscale_pyramid(self):
142 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ])
143
144 i = DoGet(ORTHANC, '/instances')
145 self.assertEqual(4, len(i))
146
147 for j in range(4):
148 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[j])
149 self.assertEqual(64, int(tags['Columns']))
150 self.assertEqual(64, int(tags['Rows']))
151 self.assertEqual('MONOCHROME2', tags['PhotometricInterpretation'])
152
153 s = DoGet(ORTHANC, '/series')
154 self.assertEqual(1, len(s))
155
156 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
157 self.assertEqual(s[0], pyramid['ID'])
158 self.assertEqual(4, len(pyramid['Resolutions']))
159 self.assertEqual(4, len(pyramid['Sizes']))
160 self.assertEqual(4, len(pyramid['TilesCount']))
161 self.assertEqual(1, pyramid['Resolutions'][0])
162 self.assertEqual(2, pyramid['Resolutions'][1])
163 self.assertEqual(4, pyramid['Resolutions'][2])
164 self.assertEqual(8, pyramid['Resolutions'][3])
165 self.assertEqual(512, pyramid['Sizes'][0][0])
166 self.assertEqual(512, pyramid['Sizes'][0][1])
167 self.assertEqual(256, pyramid['Sizes'][1][0])
168 self.assertEqual(256, pyramid['Sizes'][1][1])
169 self.assertEqual(128, pyramid['Sizes'][2][0])
170 self.assertEqual(128, pyramid['Sizes'][2][1])
171 self.assertEqual(64, pyramid['Sizes'][3][0])
172 self.assertEqual(64, pyramid['Sizes'][3][1])
173 self.assertEqual(64, pyramid['TileWidth'])
174 self.assertEqual(64, pyramid['TileHeight'])
175 self.assertEqual(512, pyramid['TotalWidth'])
176 self.assertEqual(512, pyramid['TotalHeight'])
177 self.assertEqual(8, pyramid['TilesCount'][0][0])
178 self.assertEqual(8, pyramid['TilesCount'][0][1])
179 self.assertEqual(4, pyramid['TilesCount'][1][0])
180 self.assertEqual(4, pyramid['TilesCount'][1][1])
181 self.assertEqual(2, pyramid['TilesCount'][2][0])
182 self.assertEqual(2, pyramid['TilesCount'][2][1])
183 self.assertEqual(1, pyramid['TilesCount'][3][0])
184 self.assertEqual(1, pyramid['TilesCount'][3][1])
185
186 try:
187 print('\nStarting the tests...')
188 unittest.main(argv = [ sys.argv[0] ] + args.options)
189
190 finally:
191 print('\nDone')