Mercurial > hg > orthanc-tests
annotate Plugins/Worklists/Run.py @ 95:a807a4699eb4
testing of metadata SopClassUid
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Dec 2016 14:49:23 +0100 |
parents | 09afe3616660 |
children | c39520dacdd7 |
rev | line source |
---|---|
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
2 # -*- coding: utf-8 -*- |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
3 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Orthanc - A Lightweight, RESTful DICOM Store |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 # Department, University Hospital of Liege, Belgium |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 # This program is free software: you can redistribute it and/or |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 # modify it under the terms of the GNU General Public License as |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # published by the Free Software Foundation, either version 3 of the |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 # License, or (at your option) any later version. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 # This program is distributed in the hope that it will be useful, but |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 # WITHOUT ANY WARRANTY; without even the implied warranty of |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 # General Public License for more details. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 # |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 # You should have received a copy of the GNU General Public License |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 import argparse |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import os |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import pprint |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import re |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import subprocess |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import sys |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 import tempfile |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 import unittest |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 from Toolbox import * |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 ## Parse the command-line arguments |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 parser = argparse.ArgumentParser(description = 'Run the integration tests for the DICOM worklist plugin.') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 parser.add_argument('--server', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 default = 'localhost', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 help = 'Address of the Orthanc server to test') |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
45 parser.add_argument('--rest', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
46 type = int, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
47 default = 8042, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
48 help = 'Port to the REST API') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
49 parser.add_argument('--username', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
50 default = 'alice', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
51 help = 'Username to the REST API') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
52 parser.add_argument('--password', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
53 default = 'orthanctest', |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
54 help = 'Password to the REST API') |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 parser.add_argument('--dicom', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 type = int, |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 default = 4242, |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 help = 'DICOM port of the Orthanc instance to test') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 parser.add_argument('options', metavar = 'N', nargs = '*', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 help='Arguments to Python unittest') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 args = parser.parse_args() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
66 ORTHANC = DefineOrthanc(server = args.server, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
67 username = args.username, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
68 password = args.password, |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
69 restPort = args.rest) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
70 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
71 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
72 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 ## Toolbox |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 DATABASE = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..', 'Database', 'Worklists'))) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 WORKING = os.path.join(DATABASE, 'Working') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 try: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 os.mkdir(WORKING) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 except Exception as e: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 # The working folder has already been created |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 pass |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 def ClearDatabase(): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 for f in os.listdir(WORKING): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 if f != 'lockfile': |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 os.remove(os.path.join(WORKING, f)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 def AddToDatabase(source): |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
92 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 os.path.join(DATABASE, source), |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 os.path.join(WORKING, os.path.basename(source) + '.wl') ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 def RunQuery(source, ignoreTags): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 with tempfile.NamedTemporaryFile() as f: |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
98 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 os.path.join(DATABASE, source), f.name ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 a = subprocess.check_output([ 'findscu', '-v', '--call', 'ORTHANC', '-aet', 'ORTHANCTEST', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 args.server, str(args.dicom), f.name ], |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 stderr = subprocess.STDOUT).splitlines() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 if len(filter(lambda x: x.startswith('E:'), a)) > 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 raise Exception('Error while running findscu') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 b = map(lambda x: x[3:], filter(lambda x: x.startswith('W: ---') or x.startswith('W: ('), a)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 b = map(lambda x: re.sub(r'\s*#.*', '', x), b) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 answers = [] |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 current = [] |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 for l in b: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 if l[0] == '-': |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 # This is a separator between DICOM datasets |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 if len(current) > 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 answers.append(current) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 current = [] |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 else: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 tag = l[1:10].lower() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 if not tag in ignoreTags: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 current.append(l) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 if len(current) > 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 answers.append(current) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 return answers |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 def CompareAnswers(expected, actual): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 if len(expected) != len(actual): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 return False |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 if len(expected) == 0: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 return True |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 for i in range(len(expected)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 for j in range(len(actual)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 if expected[i] == actual[j]: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 return True |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 return False |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
146 def ParseTopLevelTags(answer): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
147 tags = {} |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
148 for line in answer: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
149 m = re.match(r'^\(([0-9a-f]{4},[0-9a-f]{4})\)\s*..\s*\[([^]]*)\]', line) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
150 tags[m.group(1)] = m.group(2).strip() |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
151 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
152 return tags |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
153 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
154 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 ## The tests |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 ## |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 class Orthanc(unittest.TestCase): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 def setUp(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 if (sys.version_info >= (3, 0)): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 # Remove annoying warnings about unclosed socket in Python 3 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 import warnings |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 warnings.simplefilter("ignore", ResourceWarning) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 ClearDatabase() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 def test_single(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 for db in range(1, 11): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 ClearDatabase() |
91 | 172 AddToDatabase('Dcmtk/Database/wklist%d.dump' % db) |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 for query in range(0, 13): |
91 | 175 answers = RunQuery('Dcmtk/Queries/wlistqry%d.dump' % query, [ |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 '0008,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 '0040,0004', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 '0040,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 '0040,0020', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
91 | 182 with open(os.path.join('%s/Dcmtk/Expected/single-%d-%d.json' % (DATABASE, db, query)), 'r') as f: |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 expected = json.loads(f.read()) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 self.assertTrue(CompareAnswers(expected, answers)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 def test_all(self): |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 ClearDatabase() |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 for db in range(1, 11): |
91 | 191 AddToDatabase('Dcmtk/Database/wklist%d.dump' % db) |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 for query in range(0, 13): |
91 | 194 answers = RunQuery('Dcmtk/Queries/wlistqry%d.dump' % query, [ |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 '0008,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 '0040,0004', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 '0040,0005', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 '0040,0020', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 ]) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 |
91 | 201 with open(os.path.join('%s/Dcmtk/Expected/all-%d.json' % (DATABASE, query)), 'r') as f: |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 expected = json.loads(f.read()) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 self.assertTrue(CompareAnswers(expected, answers)) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
206 def test_vet(self): |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
207 AddToDatabase('Sequences/STATION_AET/orig.7705.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
208 AddToDatabase('Sequences/STATION_AET/orig.7814.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
209 AddToDatabase('Sequences/STATION_AET/orig.7814.without.seq.dump') |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
210 |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
211 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.length.dump', []))) |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
212 self.assertEqual(2, len(RunQuery('Sequences/Queries/7814.without.seq.dump', []))) |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
213 self.assertEqual(2, len(RunQuery('Sequences/Queries/orig.7814.dump', []))) |
95
a807a4699eb4
testing of metadata SopClassUid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
94
diff
changeset
|
214 #self.assertEqual(2, len(RunQuery('Sequences/Queries/orig.7814.without.station.aet.dump', []))) |
93
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
215 |
fff2b4a24b5f
test of sequences in worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
216 |
94
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
217 def test_encodings(self): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
218 # Check out ../../Database/Worklists/Encodings/database.dump |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
219 TEST = u'Test-éüäöòДΘĝדصķћ๛ネİ' |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
220 ENCODINGS = { |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
221 'Arabic' : [ 'ISO_IR 127' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
222 'Ascii' : [ 'ISO_IR 6' ], # More accurately, ISO 646 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
223 'Cyrillic' : [ 'ISO_IR 144' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
224 'Greek' : [ 'ISO_IR 126' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
225 'Hebrew' : [ 'ISO_IR 138' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
226 'Japanese' : [ 'ISO_IR 13', 'shift-jis' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
227 'Latin1' : [ 'ISO_IR 100' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
228 'Latin2' : [ 'ISO_IR 101' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
229 'Latin3' : [ 'ISO_IR 109' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
230 'Latin4' : [ 'ISO_IR 110' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
231 'Latin5' : [ 'ISO_IR 148' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
232 'Thai' : [ 'ISO_IR 166', 'tis-620' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
233 'Utf8' : [ 'ISO_IR 192' ], |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
234 } |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
235 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
236 AddToDatabase('Encodings/database.dump') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
237 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
238 for name, encoding in ENCODINGS.iteritems(): |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
239 self.assertEqual(name, DoPut(ORTHANC, '/tools/default-encoding', name)) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
240 result = RunQuery('Encodings/query.dump', []) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
241 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
242 self.assertEqual(1, len(result)) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
243 self.assertEqual(2, len(result[0])) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
244 tags = ParseTopLevelTags(result[0]) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
245 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
246 if len(encoding) == 1: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
247 encoded = TEST.encode(name, 'ignore') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
248 else: |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
249 encoded = TEST.encode(encoding[1], 'ignore') |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
250 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
251 self.assertEqual(encoding[0], tags['0008,0005']) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
252 self.assertEqual(encoded, tags['0010,0010']) |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
253 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
254 |
09afe3616660
Orthanc.test_encodings for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
93
diff
changeset
|
255 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 try: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 print('\nStarting the tests...') |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 unittest.main(argv = [ sys.argv[0] ] + args.options) |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 finally: |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 print('\nDone') |