예제 #1
0
class TestLocalWorkdir(UnittestPythonCompatibility):
    def setUp(self):
        """
        Build two task workflow
        """

        self.wf = Workflow(project_dir=tmp_project_dir)

        tid1 = self.wf.add_task(
            'test1', custom_func="module.dummy_task_runners.task_runner")
        tid1.set_input(add_number=10, dummy=2)

        tid2 = self.wf.add_task(
            'test2', custom_func="module.dummy_task_runners.task_runner")
        tid2.set_input(add_number=8, output_to_disk=True)
        self.wf.connect_task(tid1.nid, tid2.nid)

    def tearDown(self):
        """
        tearDown method called after each unittest to cleanup
        the project directory
        """

        if os.path.exists(tmp_project_dir):
            shutil.rmtree(tmp_project_dir)

    def test_store_output_all(self):
        """
        Test run workflow storing output of all tasks (default)
        """

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check existence of project dir, tasks dirs and workflow graph file.
        self.assertTrue(os.path.exists(tmp_project_dir))
        self.assertEqual(
            len([d for d in os.listdir(tmp_project_dir) if os.path.isdir(d)]),
            2)
        self.assertTrue(
            os.path.isfile(os.path.join(tmp_project_dir, 'workflow.jgf')))

        # Check output
        expected = {'test1': 12, 'test2': 20}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])

    def test_store_output_partial(self):
        """
        Test run workflow storing output only for last task
        """

        task = self.wf.get_task(key='test1')
        task.task_metadata.store_output.value = False

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check existence of project dir, tasks dirs and workflow graph file.
        self.assertTrue(os.path.exists(tmp_project_dir))
        self.assertEqual(
            len([d for d in os.listdir(tmp_project_dir) if os.path.isdir(d)]),
            1)
        self.assertTrue(
            os.path.isfile(os.path.join(tmp_project_dir, 'workflow.jgf')))

        # Check output
        expected = {'test1': 12, 'test2': 20}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])
예제 #2
0
class TestInputOutputMapping(UnittestPythonCompatibility):
    def setUp(self):
        """
        Build a two task workflow
        """

        self.wf = Workflow()

        self.tid1 = self.wf.add_task(
            'test1',
            custom_func="module.dummy_task_runners.task_runner",
            store_output=False)
        self.tid1.set_input(add_number=10, dummy=2, return_more=True)

        self.tid2 = self.wf.add_task(
            'test2',
            custom_func="module.dummy_task_runners.task_runner",
            store_output=False)
        self.tid2.set_input(add_number=8, return_more=True)

    def test_run_default(self):
        """
        Test run workflow storing output of all tasks.
        Default task connection communicates all results
        """

        # Default task connect
        self.wf.connect_task(self.tid1.nid, self.tid2.nid)

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check expected output. All output should be returned
        expected = {'test1': 12, 'test2': 20}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])

    def test_run_keyword_selection(self):
        """
        Test run workflow storing output of all tasks
        Task connection communicating only the 'dummy' output variable
        """

        # Connect tasks with keyword selection
        self.wf.connect_task(self.tid1.nid, self.tid2.nid, 'dummy')

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check expected output.
        expected = {'test1': 12, 'test2': 20}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])

    def test_run_keyword_mapping(self):
        """
        Test run workflow storing output of all tasks
        Task connection translates the param3 parameter to 'dummy'
        """

        # Connect tasks with keyword selection and mapping
        self.wf.connect_task(self.tid1.nid, self.tid2.nid, param3='dummy')

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check expected output.
        expected = {'test1': 12, 'test2': 13}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])

    def test_run_keyword_selection_mapping(self):
        """
        Test run workflow storing output of all tasks
        Task connection communicating the 'dummy' and 'param3' output variables
        where param3 is translated to 'dummy', replacing default 'dummy'
        """

        # Connect tasks with keyword selection and mapping
        self.wf.connect_task(self.tid1.nid,
                             self.tid2.nid,
                             'dummy',
                             param3='dummy')

        # Run the workflow
        self.wf.run()

        # Blocking: wait until workflow is no longer running
        while self.wf.is_running:
            time.sleep(2)

        # Check expected output.
        expected = {'test1': 12, 'test2': 13}
        for task in self.wf.get_tasks():
            self.assertEqual(task.get_output().get('dummy'),
                             expected[task.key])