def create_spec_from_xml(filename): """ create workflow spec from given xml file """ serializer = XmlSerializer() with open(filename) as f: xml_data = f.read() wf_spec = serializer.deserialize_workflow_spec(xml_data, filename) return wf_spec
def load_workflow_spec(self, folder, f): file = os.path.join(os.path.dirname(__file__), '..', 'data', 'spiff', folder, f) serializer = XmlSerializer() xml = open(file).read() self.wf_spec = WorkflowSpec.deserialize(serializer, xml, filename=file) self.workflow = Workflow(self.wf_spec)
def setUp(self): Task.id_pool = 0 Task.thread_id_pool = 0 self.xml_path = [ 'data/spiff/control-flow', 'data/spiff/data', 'data/spiff/resource', 'data/spiff' ] self.serializer = XmlSerializer()
def _create_subworkflow(self, my_task): from SpiffWorkflow.storage import XmlSerializer from SpiffWorkflow.specs import WorkflowSpec file = valueof(my_task, self.file) serializer = XmlSerializer() xml = open(file).read() wf_spec = WorkflowSpec.deserialize(serializer, xml, filename=file) outer_workflow = my_task.workflow.outer_workflow return SpiffWorkflow.Workflow(wf_spec, parent=outer_workflow)
def testBeginWorkflowStepByStep(self): """ Simulates interactive calls, as would be issued by a user. """ xml_file = os.path.join(data_dir, 'spiff', 'workflow1.xml') xml = open(xml_file).read() wf_spec = WorkflowSpec.deserialize(XmlSerializer(), xml) workflow = Workflow(wf_spec) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 1) self.assertEqual(tasks[0].task_spec.name, 'Start') workflow.complete_task_from_id(tasks[0].id) self.assertEqual(tasks[0].state, Task.COMPLETED) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 2) task_a1 = tasks[0] task_b1 = tasks[1] self.assertEqual(task_a1.task_spec.__class__, Simple) self.assertEqual(task_a1.task_spec.name, 'task_a1') self.assertEqual(task_b1.task_spec.__class__, Simple) self.assertEqual(task_b1.task_spec.name, 'task_b1') workflow.complete_task_from_id(task_a1.id) self.assertEqual(task_a1.state, Task.COMPLETED) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 2) self.assertTrue(task_b1 in tasks) task_a2 = tasks[0] self.assertEqual(task_a2.task_spec.__class__, Simple) self.assertEqual(task_a2.task_spec.name, 'task_a2') workflow.complete_task_from_id(task_a2.id) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 1) self.assertTrue(task_b1 in tasks) workflow.complete_task_from_id(task_b1.id) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 1) workflow.complete_task_from_id(tasks[0].id) tasks = workflow.get_tasks(Task.READY) self.assertEqual(len(tasks), 1) self.assertEqual(tasks[0].task_spec.name, 'synch_1')
def _on_ready_before_hook(self, my_task): from SpiffWorkflow.storage import XmlSerializer from SpiffWorkflow.specs import WorkflowSpec file = valueof(my_task, self.file) serializer = XmlSerializer() xml = open(file).read() wf_spec = WorkflowSpec.deserialize(serializer, xml, filename=file) outer_workflow = my_task.workflow.outer_workflow subworkflow = SpiffWorkflow.Workflow(wf_spec, parent=outer_workflow) subworkflow.completed_event.connect(self._on_subworkflow_completed, my_task) # Integrate the tree of the subworkflow into the tree of this workflow. my_task._sync_children(self.outputs, Task.FUTURE) for child in my_task.children: child.task_spec._update_state(child) child._inherit_attributes() for child in subworkflow.task_tree.children: my_task.children.insert(0, child) child.parent = my_task my_task._set_internal_attribute(subworkflow=subworkflow)
def testConstructor(self): XmlSerializer()
def setUp(self): SerializerTest.setUp(self) self.serializer = XmlSerializer() self.serial_type = str
import sys import unittest data_dir = os.path.join(os.path.dirname(__file__), '..', 'data') sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..')) import pickle from random import randint try: from util import track_workflow except ImportError as e: from tests.SpiffWorkflow.util import track_workflow from SpiffWorkflow import Workflow from SpiffWorkflow.specs import Join, WorkflowSpec from SpiffWorkflow.storage import XmlSerializer serializer = XmlSerializer() data_file = 'data.pkl' class WorkflowSpecTest(unittest.TestCase): CORRELATE = WorkflowSpec def setUp(self): self.wf_spec = WorkflowSpec() def testConstructor(self): spec = WorkflowSpec('my spec') self.assertEqual('my spec', spec.name) def testGetTaskSpecFromName(self): pass #FIXME
def setUp(self): self.serializer = XmlSerializer() self.data_file = 'data.pkl'