def test_call_scatter(self): sc = WorkflowScatter( "i", "integers", [ WorkflowCall(Task("task1").name, inputs_map={"num": "i"}), WorkflowCall(Task("task2").name, inputs_map={"num": "task1.output"}), ], ) print(sc.get_string(indent=0)) print(sc.get_string(indent=1)) print(sc.get_string(indent=2))
def test_readme_task(self): t = Task("task_name") t.inputs.append(Input(WdlType.parse_type("String"), "taskGreeting")) # command in next section t.outputs.append( Output(WdlType.parse_type("File"), "standardOut", "stdout()")) command = Task.Command("echo") command.inputs.append( Task.Command.CommandInput( "taskGreeting", optional=False, position=None, prefix="-a", separate_value_from_prefix=True, default=None, )) command.inputs.append( Task.Command.CommandInput( "otherInput", optional=True, position=2, prefix="optional-param=", separate_value_from_prefix=False, default=None, )) # t is the task t.command = command print(t.get_string())
def test_meta_string(self): w = Task("meta_string", meta=Meta(author="illusional")) expected = """\ task meta_string { meta { author: "illusional" } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def test_meta_scalar(self): w = Task("meta_scalar", meta=Meta(arbitrary_scalar=42)) expected = """\ task meta_scalar { meta { arbitrary_scalar: 42 } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def test_parameter_meta_scalar(self): w = Task("param_meta_scalar", parameter_meta=ParameterMeta(test=42)) expected = """\ task param_meta_scalar { parameter_meta { test: 42 } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def test_meta_bool(self): w = Task("meta_scalar", meta=Meta(pos=True, neg=False)) expected = """\ task meta_scalar { meta { pos: true neg: false } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def test_parameter_meta_string(self): w = Task("param_meta_string", parameter_meta=ParameterMeta(other="string value")) expected = """\ task param_meta_string { parameter_meta { other: "string value" } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def save_to_string(self, cmd: Command) -> str: inputs: List[CliArgument] = [*cmd.named] + ( [] if self.ignore_positionals else [*cmd.positional]) names = self.choose_variable_names(inputs) tool = Task( name=self.make_task_name(cmd), command=self.make_command(cmd, names), version="1.0", inputs=self.make_inputs(names), parameter_meta=self.make_parameter_meta(names), ) return tool.get_string()
def test_parameter_meta_obj(self): w = Task( "param_meta_obj", parameter_meta=ParameterMeta( obj_value=ParameterMeta.ParamMetaAttribute( help="This is help text", scalar=96)), ) expected = """\ task param_meta_obj { parameter_meta { obj_value: {help: "This is help text", scalar: 96} } }""" derived_workflow_only = "".join( w.get_string().splitlines(keepends=True)[2:]) self.assertEqual(expected, derived_workflow_only)
def test_simple_task(self): # Task based on: https://github.com/openwdl/wdl/blob/master/versions/draft-2/SPEC.md#introduction t = Task("hello", runtime=Task.Runtime(docker="broadinstitute/my_image")) t.inputs.extend([ Input(WdlType.parse_type("String"), "pattern"), Input(WdlType.parse_type("File"), "in"), ]) t.outputs.append( Output(WdlType.parse_type("Array[String]"), "matches", "read_lines(stdout())")) t.command = Task.Command( "egrep", inputs=[Task.Command.CommandInput.from_input(i) for i in t.inputs]) print(t.get_string()) return t
def test_hello_tasks(): # https://github.com/openwdl/wdl/#specifying-inputs-and-using-declarations t1 = Task( "hello", inputs=[Input(String, "name"), Input(String, "salutation")], outputs=[Output(String, "response", "read_string(stdout())")], ) t1.command = Task.Command( "echo", inputs=[ Task.Command.CommandInput.from_input(t1.inputs[i], position=i) for i in range(2) ], ) print(t1.get_string()) return t1