comparison Tests/Tests.py @ 44:ffa542cce638

Toolbox.FindExecutable()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Aug 2015 11:57:16 +0200
parents 5f3bcdde2461
children a8cc12e9b268
comparison
equal deleted inserted replaced
43:5f3bcdde2461 44:ffa542cce638
40 40
41 def ExtractDicomTags(rawDicom, tags): 41 def ExtractDicomTags(rawDicom, tags):
42 with tempfile.NamedTemporaryFile(delete = True) as f: 42 with tempfile.NamedTemporaryFile(delete = True) as f:
43 f.write(rawDicom) 43 f.write(rawDicom)
44 f.flush() 44 f.flush()
45 data = subprocess.check_output([ 'dcm2xml', f.name ]) 45 data = subprocess.check_output([ Toolbox.FindExecutable('dcm2xml'), f.name ])
46 46
47 result = [] 47 result = []
48 for tag in tags: 48 for tag in tags:
49 match = re.search('<element[^>]+name="%s">([^>]*)</element>' % tag, data) 49 match = re.search('<element[^>]+name="%s">([^>]*)</element>' % tag, data)
50 if match == None: 50 if match == None:
83 class Orthanc(unittest.TestCase): 83 class Orthanc(unittest.TestCase):
84 def setUp(self): 84 def setUp(self):
85 DropOrthanc(_LOCAL) 85 DropOrthanc(_LOCAL)
86 DropOrthanc(_REMOTE) 86 DropOrthanc(_REMOTE)
87 UninstallLuaCallbacks() 87 UninstallLuaCallbacks()
88 #print "In test", self._testMethodName 88 print "In test", self._testMethodName
89 89
90 def AssertSameImages(self, truth, url): 90 def AssertSameImages(self, truth, url):
91 im = GetImage(_REMOTE, url) 91 im = GetImage(_REMOTE, url)
92 self.assertTrue(CompareLists(truth, im.getdata())) 92 self.assertTrue(CompareLists(truth, im.getdata()))
93 93
94 94
399 except: 399 except:
400 # The file does not exist 400 # The file does not exist
401 pass 401 pass
402 402
403 z.extract('DICOMDIR', '/tmp') 403 z.extract('DICOMDIR', '/tmp')
404 a = subprocess.check_output([ 'dciodvfy', '/tmp/DICOMDIR' ], 404 a = subprocess.check_output([ Toolbox.FindExecutable('dciodvfy'), '/tmp/DICOMDIR' ],
405 stderr = subprocess.STDOUT).split('\n') 405 stderr = subprocess.STDOUT).split('\n')
406 self.assertEqual(3, len(a)) 406 self.assertEqual(3, len(a))
407 self.assertTrue(a[0].startswith('Warning')) 407 self.assertTrue(a[0].startswith('Warning'))
408 self.assertEqual('BasicDirectory', a[1]) 408 self.assertEqual('BasicDirectory', a[1])
409 self.assertEqual('', a[2]) 409 self.assertEqual('', a[2])
410 410
411 a = subprocess.check_output([ 'dcentvfy', '/tmp/DICOMDIR' ], 411 a = subprocess.check_output([ Toolbox.FindExecutable('dcentvfy'), '/tmp/DICOMDIR' ],
412 stderr = subprocess.STDOUT).split('\n') 412 stderr = subprocess.STDOUT).split('\n')
413 self.assertEqual(1, len(a)) 413 self.assertEqual(1, len(a))
414 self.assertEqual('', a[0]) 414 self.assertEqual('', a[0])
415 415
416 a = subprocess.check_output([ 'dcm2xml', '/tmp/DICOMDIR' ]) 416 a = subprocess.check_output([ Toolbox.FindExecutable('dcm2xml'), '/tmp/DICOMDIR' ])
417 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081908590448738', a) != None) 417 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081908590448738', a) != None)
418 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081909113806560', a) != None) 418 self.assertTrue(re.search('1.3.46.670589.11.17521.5.0.3124.2008081909113806560', a) != None)
419 419
420 os.remove('/tmp/DICOMDIR') 420 os.remove('/tmp/DICOMDIR')
421 421
976 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize'])) 976 self.assertEqual(size, int(DoGet(_REMOTE, '/statistics')['TotalDiskSize']))
977 977
978 978
979 def test_incoming_storescu(self): 979 def test_incoming_storescu(self):
980 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) 980 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))
981 subprocess.check_call([ 'storescu', _REMOTE['Server'], str(_REMOTE['DicomPort']), 981 subprocess.check_call([ Toolbox.FindExecutable('storescu'),
982 _REMOTE['Server'], str(_REMOTE['DicomPort']),
982 GetDatabasePath('ColorTestImageJ.dcm') ]) 983 GetDatabasePath('ColorTestImageJ.dcm') ])
983 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) 984 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
984 985
985 986
986 def test_incoming_findscu(self): 987 def test_incoming_findscu(self):
987 def CallFindScu(args): 988 def CallFindScu(args):
988 p = subprocess.Popen([ 'findscu', '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'], 989 p = subprocess.Popen([ Toolbox.FindExecutable('findscu'),
990 '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'],
989 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, 991 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args,
990 stderr=subprocess.PIPE) 992 stderr=subprocess.PIPE)
991 return p.communicate()[1] 993 return p.communicate()[1]
992 994
993 UploadInstance(_REMOTE, 'Multiframe.dcm') 995 UploadInstance(_REMOTE, 'Multiframe.dcm')
1015 self.assertEqual(1, len(series)) 1017 self.assertEqual(1, len(series))
1016 1018
1017 1019
1018 def test_incoming_movescu(self): 1020 def test_incoming_movescu(self):
1019 def CallMoveScu(args): 1021 def CallMoveScu(args):
1020 subprocess.check_call([ 'movescu', 1022 subprocess.check_call([ Toolbox.FindExecutable('movescu'),
1021 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp) 1023 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp)
1022 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc) 1024 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc)
1023 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp) 1025 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp)
1024 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, 1026 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args,
1025 stderr=subprocess.PIPE) 1027 stderr=subprocess.PIPE)
1745 self.assertEqual(1, len(i)) 1747 self.assertEqual(1, len(i))
1746 1748
1747 with tempfile.NamedTemporaryFile(delete = True) as f: 1749 with tempfile.NamedTemporaryFile(delete = True) as f:
1748 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0])) 1750 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0]))
1749 f.flush() 1751 f.flush()
1750 routed = subprocess.check_output([ 'dcm2xml', f.name ]) 1752 routed = subprocess.check_output([ Toolbox.FindExecutable('dcm2xml'), f.name ])
1751 self.assertEqual('My Medical Device', re.search('"StationName">(.*?)<', routed).group(1).strip()) 1753 self.assertEqual('My Medical Device', re.search('"StationName">(.*?)<', routed).group(1).strip())
1752 self.assertEqual(None, re.search('"MilitaryRank"', routed)) 1754 self.assertEqual(None, re.search('"MilitaryRank"', routed))
1753 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag 1755 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag
1754 1756
1755 1757
1839 1841
1840 1842
1841 def test_incoming_jpeg(self): 1843 def test_incoming_jpeg(self):
1842 def storescu(): 1844 def storescu():
1843 with open(os.devnull, 'w') as FNULL: 1845 with open(os.devnull, 'w') as FNULL:
1844 subprocess.check_call([ 'storescu', '-xs', 1846 subprocess.check_call([ Toolbox.FindExecutable('storescu'), '-xs',
1845 _REMOTE['Server'], str(_REMOTE['DicomPort']), 1847 _REMOTE['Server'], str(_REMOTE['DicomPort']),
1846 GetDatabasePath('Knix/Loc/IM-0001-0001.dcm') ], 1848 GetDatabasePath('Knix/Loc/IM-0001-0001.dcm') ],
1847 stderr = FNULL) 1849 stderr = FNULL)
1848 1850
1849 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) 1851 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))