annotate Plugins/WSI/Run.py @ 252:01db33301c3d

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