comparison Tests/Tests.py @ 45:a8cc12e9b268

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Aug 2015 12:02:19 +0200
parents ffa542cce638
children 85b2e36ed392
comparison
equal deleted inserted replaced
44:ffa542cce638 45:a8cc12e9b268
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([ Toolbox.FindExecutable('dcm2xml'), f.name ]) 45 data = subprocess.check_output([ 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
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([ Toolbox.FindExecutable('dciodvfy'), '/tmp/DICOMDIR' ], 404 a = subprocess.check_output([ 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([ Toolbox.FindExecutable('dcentvfy'), '/tmp/DICOMDIR' ], 411 a = subprocess.check_output([ 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([ Toolbox.FindExecutable('dcm2xml'), '/tmp/DICOMDIR' ]) 416 a = subprocess.check_output([ 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([ Toolbox.FindExecutable('storescu'), 981 subprocess.check_call([ FindExecutable('storescu'),
982 _REMOTE['Server'], str(_REMOTE['DicomPort']), 982 _REMOTE['Server'], str(_REMOTE['DicomPort']),
983 GetDatabasePath('ColorTestImageJ.dcm') ]) 983 GetDatabasePath('ColorTestImageJ.dcm') ])
984 self.assertEqual(1, len(DoGet(_REMOTE, '/patients'))) 984 self.assertEqual(1, len(DoGet(_REMOTE, '/patients')))
985 985
986 986
987 def test_incoming_findscu(self): 987 def test_incoming_findscu(self):
988 def CallFindScu(args): 988 def CallFindScu(args):
989 p = subprocess.Popen([ Toolbox.FindExecutable('findscu'), 989 p = subprocess.Popen([ FindExecutable('findscu'),
990 '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'], 990 '-P', '-aec', _REMOTE['DicomAet'], '-aet', _LOCAL['DicomAet'],
991 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, 991 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args,
992 stderr=subprocess.PIPE) 992 stderr=subprocess.PIPE)
993 return p.communicate()[1] 993 return p.communicate()[1]
994 994
1017 self.assertEqual(1, len(series)) 1017 self.assertEqual(1, len(series))
1018 1018
1019 1019
1020 def test_incoming_movescu(self): 1020 def test_incoming_movescu(self):
1021 def CallMoveScu(args): 1021 def CallMoveScu(args):
1022 subprocess.check_call([ Toolbox.FindExecutable('movescu'), 1022 subprocess.check_call([ FindExecutable('movescu'),
1023 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp) 1023 '--move', _LOCAL['DicomAet'], # Target AET (i.e. storescp)
1024 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc) 1024 '--call', _REMOTE['DicomAet'], # Called AET (i.e. Orthanc)
1025 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp) 1025 '--aetitle', _LOCAL['DicomAet'], # Calling AET (i.e. storescp)
1026 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args, 1026 _REMOTE['Server'], str(_REMOTE['DicomPort']) ] + args,
1027 stderr=subprocess.PIPE) 1027 stderr=subprocess.PIPE)
1747 self.assertEqual(1, len(i)) 1747 self.assertEqual(1, len(i))
1748 1748
1749 with tempfile.NamedTemporaryFile(delete = True) as f: 1749 with tempfile.NamedTemporaryFile(delete = True) as f:
1750 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0])) 1750 f.write(DoGet(_LOCAL, '/instances/%s/file' % i[0]))
1751 f.flush() 1751 f.flush()
1752 routed = subprocess.check_output([ Toolbox.FindExecutable('dcm2xml'), f.name ]) 1752 routed = subprocess.check_output([ FindExecutable('dcm2xml'), f.name ])
1753 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())
1754 self.assertEqual(None, re.search('"MilitaryRank"', routed)) 1754 self.assertEqual(None, re.search('"MilitaryRank"', routed))
1755 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag 1755 self.assertEqual(None, re.search('"0051,0010"', routed)) # A private tag
1756 1756
1757 1757
1841 1841
1842 1842
1843 def test_incoming_jpeg(self): 1843 def test_incoming_jpeg(self):
1844 def storescu(): 1844 def storescu():
1845 with open(os.devnull, 'w') as FNULL: 1845 with open(os.devnull, 'w') as FNULL:
1846 subprocess.check_call([ Toolbox.FindExecutable('storescu'), '-xs', 1846 subprocess.check_call([ FindExecutable('storescu'), '-xs',
1847 _REMOTE['Server'], str(_REMOTE['DicomPort']), 1847 _REMOTE['Server'], str(_REMOTE['DicomPort']),
1848 GetDatabasePath('Knix/Loc/IM-0001-0001.dcm') ], 1848 GetDatabasePath('Knix/Loc/IM-0001-0001.dcm') ],
1849 stderr = FNULL) 1849 stderr = FNULL)
1850 1850
1851 self.assertEqual(0, len(DoGet(_REMOTE, '/patients'))) 1851 self.assertEqual(0, len(DoGet(_REMOTE, '/patients')))