def runWorkflow(self, wf_spec, xml_filename): taken_path = [] for name in wf_spec.task_specs: wf_spec.task_specs[name].reached_event.connect(on_reached_cb, taken_path) wf_spec.task_specs[name].completed_event.connect(on_complete_cb, taken_path) # Execute all tasks within the Workflow workflow = Workflow(wf_spec) self.assert_(not workflow.is_completed(), "Workflow is complete before start") try: workflow.complete_all(False) except: workflow.task_tree.dump() raise # workflow.task_tree.dump() self.assert_( workflow.is_completed(), "complete_all() returned, but workflow is not complete\n" + workflow.task_tree.get_dump(), ) # Make sure that there are no waiting tasks left in the tree. for thetask in Task.Iterator(workflow.task_tree, Task.READY): workflow.task_tree.dump() raise Exception("Task with state READY: %s" % thetask.name) # Check whether the correct route was taken. filename = xml_filename + ".path" if os.path.exists(filename): file = open(filename, "r") expected = file.read() file.close() taken_path = "\n".join(taken_path) + "\n" error = "%s:\n" % name error += "Expected:\n" error += "%s\n" % expected error += "but got:\n" error += "%s\n" % taken_path self.assert_(taken_path == expected, error) # Check attribute availibility. filename = xml_filename + ".data" if os.path.exists(filename): file = open(filename, "r") expected = file.read() file.close() result = workflow.get_attribute("data", "") error = "%s:\n" % name error += "Expected:\n" error += "%s\n" % expected error += "but got:\n" error += "%s\n" % result self.assert_(result == expected, error)
def runWorkflow(self, wf_spec, xml_filename): taken_path = [] for name in wf_spec.task_specs: wf_spec.task_specs[name].reached_event.connect(on_reached_cb, taken_path) wf_spec.task_specs[name].completed_event.connect(on_complete_cb, taken_path) # Execute all tasks within the Workflow workflow = Workflow(wf_spec) self.assert_(not workflow.is_completed(), 'Workflow is complete before start') try: workflow.complete_all(False) except: workflow.task_tree.dump() raise #workflow.task_tree.dump() self.assert_(workflow.is_completed(), 'complete_all() returned, but workflow is not complete\n' + workflow.task_tree.get_dump()) # Make sure that there are no waiting tasks left in the tree. for thetask in Task.Iterator(workflow.task_tree, Task.READY): workflow.task_tree.dump() raise Exception('Task with state READY: %s' % thetask.name) # Check whether the correct route was taken. filename = xml_filename + '.path' if os.path.exists(filename): file = open(filename, 'r') expected = file.read() file.close() taken_path = '\n'.join(taken_path) + '\n' error = '%s:\n' % name error += 'Expected:\n' error += '%s\n' % expected error += 'but got:\n' error += '%s\n' % taken_path self.assert_(taken_path == expected, error) # Check attribute availibility. filename = xml_filename + '.data' if os.path.exists(filename): file = open(filename, 'r') expected = file.read() file.close() result = workflow.get_attribute('data', '') error = '%s:\n' % name error += 'Expected:\n' error += '%s\n' % expected error += 'but got:\n' error += '%s\n' % result self.assert_(result == expected, error)
def run_workflow(test, wf_spec, expected_path, expected_data, max_tries=1): # Execute all tasks within the Workflow. taken_path = track_workflow(wf_spec) workflow = Workflow(wf_spec) test.assert_(not workflow.is_completed(), 'Workflow is complete before start') try: # We allow the workflow to require a maximum of 5 seconds to # complete, to allow for testing long running tasks. for i in range(10): workflow.complete_all(False) if workflow.is_completed(): break time.sleep(0.5) except: workflow.task_tree.dump() raise #workflow.task_tree.dump() complete = False while max_tries > 0 and complete is False: max_tries -= 1 complete = workflow.is_completed() test.assert_( complete, 'complete_all() returned, but workflow is not complete\n' + workflow.task_tree.get_dump()) # Make sure that there are no waiting tasks left in the tree. for thetask in Task.Iterator(workflow.task_tree, Task.READY): workflow.task_tree.dump() raise Exception('Task with state READY: %s' % thetask.name) # Check whether the correct route was taken. if expected_path is not None: taken_path = '\n'.join(taken_path) + '\n' error = 'Expected:\n' error += '%s\n' % expected_path error += 'but got:\n' error += '%s\n' % taken_path test.assert_(taken_path == expected_path, error) # Check attribute availibility. if expected_data is not None: result = workflow.get_attribute('data', '') error = 'Expected:\n' error += '%s\n' % expected_data error += 'but got:\n' error += '%s\n' % result test.assert_(result == expected_data, error) return workflow
def run_workflow(test, wf_spec, expected_path, expected_data, max_tries=1): # Execute all tasks within the Workflow. taken_path = track_workflow(wf_spec) workflow = Workflow(wf_spec) test.assert_(not workflow.is_completed(), 'Workflow is complete before start') try: # We allow the workflow to require a maximum of 5 seconds to # complete, to allow for testing long running tasks. for i in range(10): workflow.complete_all(False) if workflow.is_completed(): break time.sleep(0.5) except: workflow.task_tree.dump() raise #workflow.task_tree.dump() complete = False while max_tries > 0 and complete is False: max_tries -= 1 complete = workflow.is_completed() test.assert_(complete, 'complete_all() returned, but workflow is not complete\n' + workflow.task_tree.get_dump()) # Make sure that there are no waiting tasks left in the tree. for thetask in Task.Iterator(workflow.task_tree, Task.READY): workflow.task_tree.dump() raise Exception('Task with state READY: %s' % thetask.name) # Check whether the correct route was taken. if expected_path is not None: taken_path = '\n'.join(taken_path) + '\n' error = 'Expected:\n' error += '%s\n' % expected_path error += 'but got:\n' error += '%s\n' % taken_path test.assert_(taken_path == expected_path, error) # Check attribute availibility. if expected_data is not None: result = workflow.get_attribute('data', '') error = 'Expected:\n' error += '%s\n' % expected_data error += 'but got:\n' error += '%s\n' % result test.assert_(result == expected_data, error) return workflow