def test_building_revsort(self):

        workflow = Workflow('revsort')
        rev_step = Step('rev', run='revtool.cwl')
        sort_step = Step('sorted', run='sorttool.cwl')

        # Add steps by chaining
        workflow.step(rev_step).step(sort_step)

        ########################################
        # Connect workflow and steps
        ########################################

        # workflow.input -> rev_step.input, workflow.reverse_sort -> sort_step.output
        workflow.\
            connect_input(rev_step, 'wf-input', 'revstep-input').\
            connect_input(sort_step, 'wf-reverse_sort', 'sortstep-reverse')

        # rev_step.output -> sort_step.input
        workflow.connect_steps(rev_step, sort_step, 'revstep-output',
                               'sortstep-input')

        # sort_step.output -> workflow.output
        workflow.connect_output(sort_step, 'sortstep-output', 'wf-output')

        yaml_string = yaml.safe_dump(workflow.save(), default_flow_style=False)
        self.assertMultiLineEqual(REVSORT_WORKFLOW, str(yaml_string))
 def test_fails_if_step_already_connected(self):
     workflow = Workflow('workflow')
     step = WorkflowStep('step')
     workflow.add_step(step)
     connection = WorkflowInputConnection(workflow, [step])
     connection.connect('workflow-input-1', ['step-input-1'])
     connection.connect('workflow-input-2', ['step-input-2'])
     with self.assertRaises(ValidationException) as cm:
         connection.connect('workflow-input-3', ['step-input-1'])
     self.assertIn('Step already has input with id: step-input-1',
                   repr(cm.exception))
 def test_connects_multiple_inputs_single_step(self):
     workflow = Workflow('workflow')
     step = WorkflowStep('step')
     workflow.add_step(step)
     connection = WorkflowInputConnection(workflow, [step])
     connection.connect('workflow-input-1', ['step-input-1'])
     connection.connect('workflow-input-2', ['step-input-2'])
     saved = workflow.save()
     step_inputs = saved['steps'][0]['in']
     self.assertEqual(step_inputs[0]['source']['id'], 'workflow-input-1')
     self.assertEqual(step_inputs[0]['id'], 'step-input-1')
     self.assertEqual(step_inputs[1]['source']['id'], 'workflow-input-2')
     self.assertEqual(step_inputs[1]['id'], 'step-input-2')
class WorkflowStepConnectionCommonTests(object):
    def setUp(self):
        self.test_cls = None
        self.workflow = Workflow('workflow-1')
        self.steps = [WorkflowStep('step-1'), WorkflowStep('step-2')]
        [self.workflow.add_step(step) for step in self.steps]

    def test_initializes_successfully(self):
        connection = self.test_cls(self.workflow, self.steps)
        self.assertIsNotNone(connection)
        self.assertEqual(connection.workflow, self.workflow)
        self.assertEqual(connection.steps, self.steps)

    def test_fails_if_steps_not_part_of_workflow(self):
        step = WorkflowStep('step-3')
        self.assertNotIn(step, self.workflow.steps)
        with self.assertRaises(ValidationException) as cm:
            self.test_cls(self.workflow, [step])
        self.assertIn('not a part of workflow', repr(cm.exception))

    def test_fails_if_not_a_workflow(self):
        with self.assertRaises(ValidationException) as cm:
            self.test_cls({}, self.steps)
        self.assertIn('not a Workflow', repr(cm.exception))

    def test_fails_if_steps_not_steps(self):
        with self.assertRaises(ValidationException) as cm:
            self.test_cls(self.workflow, [1, 2, 3])
        self.assertIn('not a WorkflowStep', repr(cm.exception))
Exemple #5
0
 def setUp(self):
     self.workflow = Workflow('my-workflow')
Exemple #6
0
 def setUp(self):
     self.workflow = Workflow('my-workflow')
     self.step1  = WorkflowStep('my-step-1')
     self.step2 = WorkflowStep('my-step-2')
Exemple #7
0
class WorkflowWithStepsTestCase(TestCase):

    def setUp(self):
        self.workflow = Workflow('my-workflow')
        self.step1  = WorkflowStep('my-step-1')
        self.step2 = WorkflowStep('my-step-2')

    def test_add_step(self):
        self.assertEqual(len(self.workflow.steps), 0)
        self.workflow.add_step(self.step1)
        self.assertEqual(len(self.workflow.steps), 1)
        self.assertIn(self.step1, self.workflow.steps)

    def test_step_convenience_method(self):
        self.assertEqual(len(self.workflow.steps), 0)
        retval = self.workflow.step(self.step2)
        self.assertEqual(len(self.workflow.steps), 1)
        self.assertIn(self.step2, self.workflow.steps)
        self.assertEqual(self.workflow, retval)

    def test_connect_input(self):
        self.workflow.add_step(self.step1)
        retval = self.workflow.connect_input(self.step1, 'wf-input', 'step-1-input')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].in_[0].id, 'step-1-input')
        self.assertEqual(retval.steps[0].in_[0].source.id, 'wf-input')

    def test_connect_input_assumes_id(self):
        self.workflow.add_step(self.step1)
        retval = self.workflow.connect_input(self.step1, 'input-1')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].in_[0].id, 'input-1')
        self.assertEqual(retval.steps[0].in_[0].source.id, 'input-1')

    def test_connect_steps(self):
        self.workflow.add_step(self.step1)
        self.workflow.add_step(self.step2)
        retval = self.workflow.connect_steps(self.step1, self.step2, 'step-1-output', 'step-2-input')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].out[0].id, 'step-1-output')
        self.assertEqual(retval.steps[1].in_[0].source, 'my-step-1/step-1-output')
        self.assertEqual(retval.steps[1].in_[0].id, 'step-2-input')

    def test_connect_steps_assumes_id(self):
        self.workflow.add_step(self.step1)
        self.workflow.add_step(self.step2)
        retval = self.workflow.connect_steps(self.step1, self.step2, 'internal')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].out[0].id, 'internal')
        self.assertEqual(retval.steps[1].in_[0].source, 'my-step-1/internal')
        self.assertEqual(retval.steps[1].in_[0].id, 'internal')

    def test_connect_output(self):
        self.workflow.add_step(self.step2)
        retval = self.workflow.connect_output(self.step2, 'step-2-output', 'wf-output')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].out[0].id, 'step-2-output')
        self.assertEqual(retval.outputs[0].outputSource, 'my-step-2/step-2-output')

    def test_connect_output_assumes_id(self):
        self.workflow.add_step(self.step2)
        retval = self.workflow.connect_output(self.step2, 'output-2')
        self.assertEqual(self.workflow, retval)
        self.assertEqual(retval.steps[0].out[0].id, 'output-2')
        self.assertEqual(retval.outputs[0].outputSource, 'my-step-2/output-2')
Exemple #8
0
class WorkflowTestCase(TestCase):

    def setUp(self):
        self.workflow = Workflow('my-workflow')

    def test_id(self):
        self.assertEqual(self.workflow.id, 'my-workflow')

    def test_save(self):
        saved = self.workflow.save()
        self.assertEqual(saved['class'], 'Workflow')
        self.assertEqual(saved['id'], 'my-workflow')

    def test_validates_add_step(self):
        with self.assertRaises(ValidationException) as cm:
            self.workflow.add_step('not-a-workflowstep')
        self.assertIn('Not a WorkflowStep', repr(cm.exception))

    def test_add_input_parameter(self):
        input_parameter = InputParameter('input-1')
        self.workflow.add_input_parameter(input_parameter)
        self.assertIn(input_parameter, self.workflow.inputs)

    def test_validates_add_input_parameter_type(self):
        with self.assertRaises(ValidationException) as cm:
            self.workflow.add_input_parameter('not-input-parameter')
        self.assertIn('Not an InputParameter', repr(cm.exception))

    def test_finds_input_parameter_by_id(self):
        input_parameter = InputParameter('input-2')
        self.workflow.add_input_parameter(input_parameter)
        self.assertEqual(input_parameter, self.workflow.input_parameter_by_id('input-2'))
        self.assertIsNone(self.workflow.input_parameter_by_id('foobar'))

    def test_add_output_parameter(self):
        output_parameter = WorkflowOutputParameter('output-1')
        self.workflow.add_output_parameter(output_parameter)
        self.assertIn(output_parameter, self.workflow.outputs)

    def test_validates_add_output_parameter(self):
        with self.assertRaises(ValidationException) as cm:
            self.workflow.add_output_parameter('not-output-parameter')
        self.assertIn('Not a WorkflowOutputParameter', repr(cm.exception))
 def setUp(self):
     self.test_cls = None
     self.workflow = Workflow('workflow-1')
     self.steps = [WorkflowStep('step-1'), WorkflowStep('step-2')]
     [self.workflow.add_step(step) for step in self.steps]
Exemple #10
0
from cwlpy import Workflow, WorkflowStep as Step, WorkflowStepConnection as Connection
from ruamel import yaml

# https://github.com/common-workflow-language/cwl-v1.1/blob/master/tests/revsort.cwl

########################################
# Create workflow and steps
########################################

workflow = Workflow('revsort')
rev_step = Step('rev', run='revtool.cwl')
sort_step = Step('sorted', run='sorttool.cwl')

# Add steps by chaining
workflow.step(rev_step).step(sort_step)

########################################
# Connect workflow and steps
########################################

# workflow.input -> rev_step.input
workflow.connect_input(rev_step, 'input')
# workflow.reverse_sort -> sort_step.output
workflow.connect_input(sort_step, 'reverse_sort', 'reverse')
# rev_step.output -> sort_step.input
workflow.connect_steps(rev_step, sort_step, 'output', 'input')
# sort_step.output -> workflow.output
workflow.connect_output(sort_step, 'output')

print(yaml.safe_dump(workflow.save(), default_flow_style=False))