comparison Plugins/Worklists/Run.py @ 109:5b6812f8cc38

worklists: test_bitbucket_issue_49
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Jun 2017 15:34:45 +0200
parents 7aee4cc64fca
children 50cd127e5330
comparison
equal deleted inserted replaced
108:7aee4cc64fca 109:5b6812f8cc38
27 import re 27 import re
28 import subprocess 28 import subprocess
29 import sys 29 import sys
30 import tempfile 30 import tempfile
31 import unittest 31 import unittest
32 from shutil import copyfile
32 33
33 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) 34 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
34 from Toolbox import * 35 from Toolbox import *
35 36
36 37
90 def ClearDatabase(): 91 def ClearDatabase():
91 for f in os.listdir(WORKING): 92 for f in os.listdir(WORKING):
92 if f != 'lockfile': 93 if f != 'lockfile':
93 os.remove(os.path.join(WORKING, f)) 94 os.remove(os.path.join(WORKING, f))
94 95
95 def AddToDatabase(source): 96 def AddToDatabase(worklist):
96 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', 97 extension = os.path.splitext(worklist)[1].lower()
97 os.path.join(DATABASE, source), 98 source = os.path.join(DATABASE, worklist)
98 os.path.join(WORKING, os.path.basename(source) + '.wl') ]) 99 target = os.path.join(WORKING, os.path.basename(worklist) + '.wl')
100
101 if extension == '.dump':
102 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', source, target ])
103 else:
104 copyfile(source, target)
105
99 106
100 def RunQuery(source, ignoreTags): 107 def RunQuery(source, ignoreTags):
101 with tempfile.NamedTemporaryFile() as f: 108 with tempfile.NamedTemporaryFile() as f:
102 subprocess.check_call([ 'dump2dcm', '--write-xfer-little', 109 subprocess.check_call([ 'dump2dcm', '--write-xfer-little',
103 os.path.join(DATABASE, source), f.name ]) 110 os.path.join(DATABASE, source), f.name ])
271 278
272 self.assertEqual(encoding[0], tags['0008,0005']) 279 self.assertEqual(encoding[0], tags['0008,0005'])
273 self.assertEqual(encoded, tags['0010,0010']) 280 self.assertEqual(encoded, tags['0010,0010'])
274 281
275 282
276 283 def test_bitbucket_issue_49(self):
277 284 def Check(encoding, expectedEncoding, expectedContent):
285 DoPut(ORTHANC, '/tools/default-encoding', encoding)
286 result = RunQuery('Encodings/issue49-latin1.query', [])
287 self.assertEqual(1, len(result))
288 self.assertEqual(2, len(result[0]))
289 tags = ParseTopLevelTags(result[0])
290 self.assertEqual(expectedEncoding, tags['0008,0005'])
291 self.assertEqual(expectedContent, tags['0010,0010'])
292
293 AddToDatabase('Encodings/issue49-latin1.wl')
294 Check('Ascii', 'ISO_IR 6', r'VANILL^LAURA^^^Mme')
295 Check('Utf8', 'ISO_IR 192', r'VANILLÉ^LAURA^^^Mme')
296 Check('Latin1', 'ISO_IR 100', u'VANILLÉ^LAURA^^^Mme'.encode('latin-1', 'ignore'))
297
278 try: 298 try:
279 print('\nStarting the tests...') 299 print('\nStarting the tests...')
280 unittest.main(argv = [ sys.argv[0] ] + args.options) 300 unittest.main(argv = [ sys.argv[0] ] + args.options)
281 301
282 finally: 302 finally: