comparison Tests/Toolbox.py @ 220:7b1c976caa9b Orthanc-1.5.5

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 25 Feb 2019 10:57:28 +0100
parents af8e034f4262
children 0f03ee6ffa80
comparison
equal deleted inserted replaced
219:00e5aeea33dd 220:7b1c976caa9b
273 return diff[0] 273 return diff[0]
274 else: 274 else:
275 print('Error while executing the job') 275 print('Error while executing the job')
276 return None 276 return None
277 277
278 def WaitAllNewJobsDone(orthanc, func): # "func" is a lambda
279 a = set(DoGet(orthanc, '/jobs'))
280 func()
281
282 first = True
283
284 while True:
285 b = set(DoGet(orthanc, '/jobs'))
286
287 diff = list(b - a)
288 if len(diff) == 0:
289 if first:
290 raise Exception('No job was created')
291 else:
292 return # We're done
293 else:
294 first = False
295
296 if WaitJobDone(orthanc, diff[0]):
297 a.add(diff[0])
298 else:
299 raise Exception('Error while executing the job')
300
301
278 def GetDockerHostAddress(): 302 def GetDockerHostAddress():
279 route = subprocess.check_output([ '/sbin/ip', 'route' ]) 303 route = subprocess.check_output([ '/sbin/ip', 'route' ])
280 m = re.search(r'default via ([0-9.]+)', route) 304 m = re.search(r'default via ([0-9.]+)', route)
281 if m == None: 305 if m == None:
282 return 'localhost' 306 return 'localhost'
333 self.thread.start() 357 self.thread.start()
334 358
335 def stop(self): 359 def stop(self):
336 self.thread_stop.set() 360 self.thread_stop.set()
337 self.thread.join() 361 self.thread.join()
362
363
364 def AssertAlmostEqualRecursive(self, a, b, places = 7):
365 if type(a) is dict:
366 self.assertTrue(type(b) is dict)
367 self.assertEqual(a.keys(), b.keys())
368 for key, value in a.items():
369 AssertAlmostEqualRecursive(self, a[key], b[key], places)
370
371 elif type(a) is list:
372 self.assertTrue(type(b) is list)
373 self.assertEqual(len(a), len(b))
374 for i in range(len(a)):
375 AssertAlmostEqualRecursive(self, a[i], b[i], places)
376
377 else:
378 self.assertAlmostEqual(a, b, places = places)