Exemple #1
0
    def setup_workflow(self, structured=True, threshold=None, cancel=False):
        wf_spec = WorkflowSpec()
        split = Simple(wf_spec, 'split')
        wf_spec.start.connect(split)

        if structured:
            join = Join(wf_spec,
                        'join',
                        threshold=threshold,
                        split_task=split.name,
                        cancel=cancel)
        else:
            join = Join(wf_spec, 'join', threshold=threshold, cancel=cancel)

        single = Simple(wf_spec, 'first', manual=True)
        default = Simple(wf_spec, 'default')
        choice = ExclusiveChoice(wf_spec, 'choice', manual=True)
        end = Simple(wf_spec, 'end')

        single.connect(join)
        join_condition = Equal(Attrib('should_join'), True)
        choice.connect_if(join_condition, join)
        choice.connect(default)

        split.connect(single)
        split.connect(choice)
        join.connect(end)

        workflow = Workflow(wf_spec)
        return workflow
Exemple #2
0
    def testAncestors(self):
        T1 = Simple(self.wf_spec, 'T1')
        T2A = Simple(self.wf_spec, 'T2A')
        T2B = Simple(self.wf_spec, 'T2B')
        M = Join(self.wf_spec, 'M')
        T3 = Simple(self.wf_spec, 'T3')

        T1.follow(self.wf_spec.start)
        T2A.follow(T1)
        T2B.follow(T1)
        T2A.connect(M)
        T2B.connect(M)
        T3.follow(M)

        self.assertEquals(T1.ancestors(), [self.wf_spec.start])
        self.assertEquals(T2A.ancestors(), [T1, self.wf_spec.start])
        self.assertEquals(T2B.ancestors(), [T1, self.wf_spec.start])
        self.assertEquals(M.ancestors(), [T2A, T1, self.wf_spec.start, T2B])
        self.assertEqual(len(T3.ancestors()), 5)
    def testAncestors(self):
        T1 = Simple(self.wf_spec, 'T1')
        T2A = Simple(self.wf_spec, 'T2A')
        T2B = Simple(self.wf_spec, 'T2B')
        M = Join(self.wf_spec, 'M')
        T3 = Simple(self.wf_spec, 'T3')

        T1.follow(self.wf_spec.start)
        T2A.follow(T1)
        T2B.follow(T1)
        T2A.connect(M)
        T2B.connect(M)
        T3.follow(M)

        self.assertEquals(T1.ancestors(), [self.wf_spec.start])
        self.assertEquals(T2A.ancestors(), [T1, self.wf_spec.start])
        self.assertEquals(T2B.ancestors(), [T1, self.wf_spec.start])
        self.assertEquals(M.ancestors(), [T2A, T1, self.wf_spec.start, T2B])
        self.assertEqual(len(T3.ancestors()), 5)
    def testAncestors(self):
        T1 = Simple(self.wf_spec, "T1")
        T2A = Simple(self.wf_spec, "T2A")
        T2B = Simple(self.wf_spec, "T2B")
        M = Join(self.wf_spec, "M")
        T3 = Simple(self.wf_spec, "T3")

        T1.follow(self.wf_spec.start)
        T2A.follow(T1)
        T2B.follow(T1)
        T2A.connect(M)
        T2B.connect(M)
        T3.follow(M)

        self.assertEquals(T1.ancestors(), [self.wf_spec.start])
        self.assertEquals(T2A.ancestors(), [T1, self.wf_spec.start])
        self.assertEquals(T2B.ancestors(), [T1, self.wf_spec.start])
        M_ancestors = M.ancestors()
        self.assertIn(T1, M_ancestors)
        self.assertIn(T2A, M_ancestors)
        self.assertIn(T2B, M_ancestors)
        self.assertIn(self.wf_spec.start, M_ancestors)
        self.assertEqual(len(T3.ancestors()), 5)
    def test_Merge_data_merging(self):
        """Test that Merge task actually merges data"""
        wf_spec = WorkflowSpec()
        first = Simple(wf_spec, 'first')
        second = Simple(wf_spec, 'second')
        third = Simple(wf_spec, 'third')
        bump = Simple(wf_spec, 'bump')
        fourth = Simple(wf_spec, 'fourth')
        merge1 = Merge(wf_spec, 'merge 1')
        simple1 = Simple(wf_spec, 'simple 1')
        merge2 = Merge(wf_spec, 'merge 2')
        simple2 = Simple(wf_spec, 'simple 2')
        unmerged = Simple(wf_spec, 'unmerged')

        wf_spec.start.connect(first)
        wf_spec.start.connect(second)
        wf_spec.start.connect(third)
        wf_spec.start.connect(bump)
        bump.connect(fourth)  # Test join at different depths in tree

        first.connect(merge1)
        second.connect(merge1)
        second.connect(unmerged)

        first.connect(merge2)
        second.connect(merge2)
        third.connect(merge2)
        fourth.connect(merge2)

        merge1.connect(simple1)
        merge2.connect(simple2)

        workflow = Workflow(wf_spec)
        workflow.task_tree.set_attribute(everywhere=1)
        for task in workflow.get_tasks():
            task.set_attribute(**{'name': task.get_name(), task.get_name(): 1})
        workflow.complete_all()
        self.assertTrue(workflow.is_completed())
        found = {}
        for task in workflow.get_tasks():
            if task.task_spec is simple1:
                self.assertIn('first', task.attributes)
                self.assertIn('second', task.attributes)
                self.assertDictEqual(task.attributes, {'Start': 1,
                        'merge 1': 1, 'name': 'Start', 'simple 1': 1,
                        'second': 1, 'first': 1})
                found['simple1'] = task
            if task.task_spec is simple2:
                self.assertIn('first', task.attributes)
                self.assertIn('second', task.attributes)
                self.assertIn('third', task.attributes)
                self.assertIn('fourth', task.attributes)
                self.assertDictEqual(task.attributes, {'merge 2': 1,
                        'simple 2': 1, 'name': 'Start', 'third': 1, 'bump': 1,
                        'Start': 1, 'second': 1, 'first': 1, 'fourth': 1})
                found['simple2'] = task
            if task.task_spec is unmerged:
                self.assertDictEqual(task.attributes, {'Start': 1,
                        'second': 1, 'name': 'Start', 'unmerged': 1})
                found['unmerged'] = task
        self.assertIn('simple1', found)
        self.assertIn('simple2', found)
        self.assertIn('unmerged', found)