コード例 #1
0
class SerializerTest(unittest.TestCase):
    CORRELATE = Serializer

    def setUp(self):
        self.wf_spec = TestWorkflowSpec()
        self.serializer = None
        self.serial_type = None

    def compare_serialized(self, state1, state2):
        return state1 == state2

    def testConstructor(self):
        Serializer()

    def testSerializeWorkflowSpec(self):
        if self.serializer is None:
            return

        # Back to back testing.
        serialized1 = self.wf_spec.serialize(self.serializer)
        wf_spec = WorkflowSpec.deserialize(self.serializer, serialized1)
        serialized2 = wf_spec.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compare_serialized(serialized1, serialized2)
        self.assertEqual(serialized1, serialized2)

        # Test whether the restored workflow still works.
        path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
        path = open(path_file).read()
        run_workflow(self, wf_spec, path, None)

    def testDeserializeWorkflowSpec(self):
        pass  # Already covered in testSerializeWorkflowSpec()

    def testSerializeWorkflow(self):
        pass  #TODO

    def testDeserializeWorkflow(self):
        pass  #TODO
コード例 #2
0
class SerializerTest(unittest.TestCase):
    CORRELATE = Serializer

    def setUp(self):
        self.wf_spec = TestWorkflowSpec()
        self.serializer = None
        self.serial_type = None

    def compare_serialized(self, state1, state2):
        return state1 == state2

    def testConstructor(self):
        Serializer()

    def testSerializeWorkflowSpec(self):
        if self.serializer is None:
            return

        # Back to back testing.
        serialized1 = self.wf_spec.serialize(self.serializer)
        wf_spec     = WorkflowSpec.deserialize(self.serializer, serialized1)
        serialized2 = wf_spec.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compare_serialized(serialized1, serialized2)
        self.assertEqual(serialized1, serialized2)

        # Test whether the restored workflow still works.
        path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
        path      = open(path_file).read()
        run_workflow(self, wf_spec, path, None)

    def testDeserializeWorkflowSpec(self):
        pass # Already covered in testSerializeWorkflowSpec()

    def testSerializeWorkflow(self):
        pass #TODO

    def testDeserializeWorkflow(self):
        pass #TODO
コード例 #3
0
ファイル: SerializerTest.py プロジェクト: 0-T-0/SpiffWorkflow
 def setUp(self):
     self.wf_spec = TestWorkflowSpec()
     self.serializer = None
     self.serial_type = None
コード例 #4
0
ファイル: SerializerTest.py プロジェクト: 0-T-0/SpiffWorkflow
class SerializerTest(unittest.TestCase):
    CORRELATE = Serializer

    def setUp(self):
        self.wf_spec = TestWorkflowSpec()
        self.serializer = None
        self.serial_type = None

    def testConstructor(self):
        Serializer()

    def testSerializeWorkflowSpec(self, path_file=None, data=None):
        if self.serializer is None:
            return

        # Back to back testing.
        try:
            serialized1 = self.wf_spec.serialize(self.serializer)
            wf_spec     = WorkflowSpec.deserialize(self.serializer, serialized1)
            serialized2 = wf_spec.serialize(self.serializer)
        except TaskSpecNotSupportedError as e:
            pass
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

            # Test whether the restored workflow still works.
            if path_file is None:
                path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
                path      = open(path_file).read()
            elif os.path.exists(path_file):
                path = open(path_file).read()
            else:
                path = None

            run_workflow(self, wf_spec, path, data)

    def compareSerialization(self, s1, s2, exclude_dynamic=False):
        if exclude_dynamic:
            warnings.warn("Asked to exclude dynamic in a compareSerialization that does not support it. The result may be wrong.")
        self.assertEqual(s1, s2)

    def testDeserializeWorkflowSpec(self):
        pass # Already covered in testSerializeWorkflowSpec()

    def testSerializeWorkflow(self, path_file=None, data=None):
        if self.serializer is None:
            return
        
        if path_file is None:
            path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
            path      = open(path_file).read()
        elif os.path.exists(path_file):
            path = open(path_file).read()
        else:
            path = None

        # run a workflow fresh from the spec to completion, see if it
        # serialises and deserialises correctly.
        workflow_without_save  = run_workflow(self, self.wf_spec, path, data)
        try:
            serialized1 = workflow_without_save.serialize(self.serializer)
            restored_wf = Workflow.deserialize(self.serializer, serialized1)
            serialized2 = restored_wf.serialize(self.serializer)
        except TaskNotSupportedError as e:
            return
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

        # try an freshly started workflow, see if it serialises and
        # deserialiases correctly. (no longer catch for exceptions: if they
        # were going to happen they should have happened already.)
        workflow = Workflow(self.wf_spec)
        serialized1 = workflow.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        self.assertFalse(restored_wf.is_completed())

        # Run it to completion, see if it serialises and deserialises correctly
        # also check if the restored and unrestored ones are the same after
        # being run through.
        workflow_unrestored = run_workflow(self, self.wf_spec, path, data, workflow=workflow)
        workflow_restored = run_workflow(self, self.wf_spec, path, data, workflow=restored_wf)

        serialized1 = workflow_restored.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        serialized_crosscheck = workflow_unrestored.serialize(self.serializer)
        self.assert_(isinstance(serialized_crosscheck, self.serial_type))
        # compare the restored and unrestored completed ones. Because they ran
        # separately, exclude the last_state_change time. Because you can have
        # dynamically created tasks, don't compare (uu)ids.
        self.compareSerialization(serialized_crosscheck, serialized2,
                                  exclude_dynamic=True)
        

    def testDeserializeWorkflow(self):
        pass # Already covered in testSerializeWorkflow()
コード例 #5
0
 def setUp(self):
     self.wf_spec = TestWorkflowSpec()
     self.serializer = None
     self.serial_type = None
コード例 #6
0
class SerializerTest(unittest.TestCase):
    CORRELATE = Serializer

    def setUp(self):
        self.wf_spec = TestWorkflowSpec()
        self.serializer = None
        self.serial_type = None

    def testConstructor(self):
        Serializer()

    def testSerializeWorkflowSpec(self, path_file=None, data=None):
        if self.serializer is None:
            return

        # Back to back testing.
        try:
            serialized1 = self.wf_spec.serialize(self.serializer)
            wf_spec = WorkflowSpec.deserialize(self.serializer, serialized1)
            serialized2 = wf_spec.serialize(self.serializer)
        except TaskSpecNotSupportedError as e:
            pass
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

            # Test whether the restored workflow still works.
            if path_file is None:
                path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
                path = open(path_file).read()
            elif os.path.exists(path_file):
                path = open(path_file).read()
            else:
                path = None

            run_workflow(self, wf_spec, path, data)

    def compareSerialization(self, s1, s2, exclude_dynamic=False):
        if exclude_dynamic:
            warnings.warn(
                "Asked to exclude dynamic in a compareSerialization that does not support it. The result may be wrong."
            )
        self.assertEqual(s1, s2)

    def testDeserializeWorkflowSpec(self):
        pass  # Already covered in testSerializeWorkflowSpec()

    def testSerializeWorkflow(self, path_file=None, data=None):
        if self.serializer is None:
            return

        if path_file is None:
            path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
            path = open(path_file).read()
        elif os.path.exists(path_file):
            path = open(path_file).read()
        else:
            path = None

        # run a workflow fresh from the spec to completion, see if it
        # serialises and deserialises correctly.
        workflow_without_save = run_workflow(self, self.wf_spec, path, data)
        try:
            serialized1 = workflow_without_save.serialize(self.serializer)
            restored_wf = Workflow.deserialize(self.serializer, serialized1)
            serialized2 = restored_wf.serialize(self.serializer)
        except TaskNotSupportedError as e:
            return
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

        # try an freshly started workflow, see if it serialises and
        # deserialiases correctly. (no longer catch for exceptions: if they
        # were going to happen they should have happened already.)
        workflow = Workflow(self.wf_spec)
        serialized1 = workflow.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        self.assertFalse(restored_wf.is_completed())

        # Run it to completion, see if it serialises and deserialises correctly
        # also check if the restored and unrestored ones are the same after
        # being run through.
        workflow_unrestored = run_workflow(self,
                                           self.wf_spec,
                                           path,
                                           data,
                                           workflow=workflow)
        workflow_restored = run_workflow(self,
                                         self.wf_spec,
                                         path,
                                         data,
                                         workflow=restored_wf)

        serialized1 = workflow_restored.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        serialized_crosscheck = workflow_unrestored.serialize(self.serializer)
        self.assert_(isinstance(serialized_crosscheck, self.serial_type))
        # compare the restored and unrestored completed ones. Because they ran
        # separately, exclude the last_state_change time. Because you can have
        # dynamically created tasks, don't compare (uu)ids.
        self.compareSerialization(serialized_crosscheck,
                                  serialized2,
                                  exclude_dynamic=True)

    def testDeserializeWorkflow(self):
        pass  # Already covered in testSerializeWorkflow()