Mercurial > hg > orthanc-tests
comparison Plugins/Worklists/Run.py @ 94:09afe3616660
Orthanc.test_encodings for worklists
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Dec 2016 11:25:17 +0100 |
parents | fff2b4a24b5f |
children | a807a4699eb4 |
comparison
equal
deleted
inserted
replaced
93:fff2b4a24b5f | 94:09afe3616660 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
2 | 4 |
3 # Orthanc - A Lightweight, RESTful DICOM Store | 5 # Orthanc - A Lightweight, RESTful DICOM Store |
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
5 # Department, University Hospital of Liege, Belgium | 7 # Department, University Hospital of Liege, Belgium |
6 # | 8 # |
38 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOM worklist plugin.') | 40 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOM worklist plugin.') |
39 | 41 |
40 parser.add_argument('--server', | 42 parser.add_argument('--server', |
41 default = 'localhost', | 43 default = 'localhost', |
42 help = 'Address of the Orthanc server to test') | 44 help = 'Address of the Orthanc server to test') |
45 parser.add_argument('--rest', | |
46 type = int, | |
47 default = 8042, | |
48 help = 'Port to the REST API') | |
49 parser.add_argument('--username', | |
50 default = 'alice', | |
51 help = 'Username to the REST API') | |
52 parser.add_argument('--password', | |
53 default = 'orthanctest', | |
54 help = 'Password to the REST API') | |
43 parser.add_argument('--dicom', | 55 parser.add_argument('--dicom', |
44 type = int, | 56 type = int, |
45 default = 4242, | 57 default = 4242, |
46 help = 'DICOM port of the Orthanc instance to test') | 58 help = 'DICOM port of the Orthanc instance to test') |
47 parser.add_argument('options', metavar = 'N', nargs = '*', | 59 parser.add_argument('options', metavar = 'N', nargs = '*', |
49 | 61 |
50 args = parser.parse_args() | 62 args = parser.parse_args() |
51 | 63 |
52 | 64 |
53 | 65 |
66 ORTHANC = DefineOrthanc(server = args.server, | |
67 username = args.username, | |
68 password = args.password, | |
69 restPort = args.rest) | |
70 | |
71 | |
72 | |
54 ## | 73 ## |
55 ## Toolbox | 74 ## Toolbox |
56 ## | 75 ## |
57 | 76 |
58 DATABASE = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..', 'Database', 'Worklists'))) | 77 DATABASE = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..', 'Database', 'Worklists'))) |
120 for j in range(len(actual)): | 139 for j in range(len(actual)): |
121 if expected[i] == actual[j]: | 140 if expected[i] == actual[j]: |
122 return True | 141 return True |
123 | 142 |
124 return False | 143 return False |
144 | |
145 | |
146 def ParseTopLevelTags(answer): | |
147 tags = {} | |
148 for line in answer: | |
149 m = re.match(r'^\(([0-9a-f]{4},[0-9a-f]{4})\)\s*..\s*\[([^]]*)\]', line) | |
150 tags[m.group(1)] = m.group(2).strip() | |
151 | |
152 return tags | |
125 | 153 |
126 | 154 |
127 ## | 155 ## |
128 ## The tests | 156 ## The tests |
129 ## | 157 ## |
183 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.length.dump', []))) | 211 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.length.dump', []))) |
184 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.seq.dump', []))) | 212 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.seq.dump', []))) |
185 self.assertEqual(2, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) | 213 self.assertEqual(2, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) |
186 | 214 |
187 | 215 |
216 def test_encodings(self): | |
217 # Check out ../../Database/Worklists/Encodings/database.dump | |
218 TEST = u'Test-éüäöòДΘĝדصķћ๛ネİ' | |
219 ENCODINGS = { | |
220 'Arabic' : [ 'ISO_IR 127' ], | |
221 'Ascii' : [ 'ISO_IR 6' ], # More accurately, ISO 646 | |
222 'Cyrillic' : [ 'ISO_IR 144' ], | |
223 'Greek' : [ 'ISO_IR 126' ], | |
224 'Hebrew' : [ 'ISO_IR 138' ], | |
225 'Japanese' : [ 'ISO_IR 13', 'shift-jis' ], | |
226 'Latin1' : [ 'ISO_IR 100' ], | |
227 'Latin2' : [ 'ISO_IR 101' ], | |
228 'Latin3' : [ 'ISO_IR 109' ], | |
229 'Latin4' : [ 'ISO_IR 110' ], | |
230 'Latin5' : [ 'ISO_IR 148' ], | |
231 'Thai' : [ 'ISO_IR 166', 'tis-620' ], | |
232 'Utf8' : [ 'ISO_IR 192' ], | |
233 } | |
234 | |
235 AddToDatabase('Encodings/database.dump') | |
236 | |
237 for name, encoding in ENCODINGS.iteritems(): | |
238 self.assertEqual(name, DoPut(ORTHANC, '/tools/default-encoding', name)) | |
239 result = RunQuery('Encodings/query.dump', []) | |
240 | |
241 self.assertEqual(1, len(result)) | |
242 self.assertEqual(2, len(result[0])) | |
243 tags = ParseTopLevelTags(result[0]) | |
244 | |
245 if len(encoding) == 1: | |
246 encoded = TEST.encode(name, 'ignore') | |
247 else: | |
248 encoded = TEST.encode(encoding[1], 'ignore') | |
249 | |
250 self.assertEqual(encoding[0], tags['0008,0005']) | |
251 self.assertEqual(encoded, tags['0010,0010']) | |
252 | |
253 | |
254 | |
188 | 255 |
189 try: | 256 try: |
190 print('\nStarting the tests...') | 257 print('\nStarting the tests...') |
191 unittest.main(argv = [ sys.argv[0] ] + args.options) | 258 unittest.main(argv = [ sys.argv[0] ] + args.options) |
192 | 259 |