changeset 318:bac7cc80f240

dicomweb: test_wado_transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 22 Jun 2020 16:15:31 +0200
parents 5ea07ecade93
children de6e73e4df60
files Plugins/DicomWeb/Run.py Tests/Tests.py Tests/Toolbox.py
diffstat 3 files changed, 52 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/DicomWeb/Run.py	Wed May 27 09:55:57 2020 +0200
+++ b/Plugins/DicomWeb/Run.py	Mon Jun 22 16:15:31 2020 +0200
@@ -1156,7 +1156,7 @@
                                       headers = { 'accept' : 'application/json' })))
 
 
-    def test_transcoding(self):
+    def test_frames_transcoding(self):
         ACCEPT = {
             '1.2.840.10008.1.2' : 'multipart/related; type=application/octet-stream; transfer-syntax=1.2.840.10008.1.2',
             '1.2.840.10008.1.2.1' : 'multipart/related; type=application/octet-stream; transfer-syntax=1.2.840.10008.1.2.1',
@@ -1285,7 +1285,45 @@
         self.assertEqual(a[0], b[0])
         self.assertEqual(a[0], b[1])
 
+
+    def test_wado_transcoding(self):
+        uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm')
+
+        self.assertRaises(Exception, lambda: DoGetMultipart(ORTHANC, '%s' % uri,
+                                                            headers = { 'Accept' : 'nope' }))
+
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = {  })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(a[0]))
+        s = len(a[0])
         
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = { 'Accept' : 'multipart/related' })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(a[0]))
+
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = { 'Accept' : 'multipart/related; type=application/dicom' })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(a[0]))
+
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = { 'Accept' : 'multipart/related; type=application/dicom; transfer-syntax=*' })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(a[0]))
+        self.assertEqual(s, len(a[0]))
+
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = { 'Accept' : 'multipart/related; type=application/dicom; transfer-syntax=1.2.840.10008.1.2.4.50' })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.4.50', GetTransferSyntax(a[0]))
+
+        a = DoGetMultipart(ORTHANC, '%s' % uri,
+                           headers = { 'Accept' : 'multipart/related; type=application/dicom; transfer-syntax=1.2.840.10008.1.2.1' })
+        self.assertEqual(1, len(a))
+        self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(a[0]))
+        self.assertTrue(10 * s < len(a[0]))
         
 try:
     print('\nStarting the tests...')
--- a/Tests/Tests.py	Wed May 27 09:55:57 2020 +0200
+++ b/Tests/Tests.py	Mon Jun 22 16:15:31 2020 +0200
@@ -111,7 +111,7 @@
 def CallMoveScu(args):
     try:
         subprocess.check_call(GetMoveScuCommand() + args,
-                              stderr=subprocess.PIPE)
+                              stderr = subprocess.PIPE)
     except subprocess.CalledProcessError as e:
         # The error code "69" corresponds to "EXITCODE_CMOVE_ERROR",
         # that has been introduced in DCMTK 3.6.2. This error code is
--- a/Tests/Toolbox.py	Wed May 27 09:55:57 2020 +0200
+++ b/Tests/Toolbox.py	Mon Jun 22 16:15:31 2020 +0200
@@ -342,14 +342,15 @@
 class ExternalCommandThread:
     @staticmethod
     def ExternalCommandFunction(arg, stop_event, command, env):
-        external = subprocess.Popen(command, env = env)
+        with open(os.devnull, 'w') as devnull:
+            external = subprocess.Popen(command, env = env, stderr = devnull)
 
-        while (not stop_event.is_set()):
-            error = external.poll()
-            if error != None:
-                # http://stackoverflow.com/a/1489838/881731
-                os._exit(-1)
-            stop_event.wait(0.1)
+            while (not stop_event.is_set()):
+                error = external.poll()
+                if error != None:
+                    # http://stackoverflow.com/a/1489838/881731
+                    os._exit(-1)
+                stop_event.wait(0.1)
 
         print('Stopping the external command')
         external.terminate()
@@ -389,7 +390,10 @@
     with tempfile.NamedTemporaryFile(delete = True) as f:
         f.write(dicom)
         f.flush()
-        data = subprocess.check_output([ FindExecutable('dcm2xml'), f.name ])
+
+        with open(os.devnull, 'w') as devnull:
+            data = subprocess.check_output([ FindExecutable('dcm2xml'), f.name ],
+                                           stderr = devnull)
 
     return re.search('<data-set xfer="(.*?)"', data).group(1)