def test_inputs_generator_secondary_files(self): w = WorkflowBuilder("tst") w.input("wsec", TestTypeWithSecondary, default="test.ext") # w._add_input(Input("wsec", TestTypeWithSecondary(), value="test.ext")) inpsdict = WdlTranslator().build_inputs_file(w, merge_resources=False) self.assertEqual("test.ext", inpsdict.get("tst.wsec")) self.assertEqual("test.txt", inpsdict.get("tst.wsec_txt"))
def test_two_similar_tools(self): w = WorkflowBuilder("testTwoToolsWithSameId") w.input("inp", str) w.step("stp1", TestTool(testtool=w.inp)) w.step("stp2", TestToolV2(testtool=w.inp)) wf_wdl, _ = WdlTranslator.translate_workflow(w) expected = """\ version development import "tools/TestTranslationtool.wdl" as T import "tools/TestTranslationtool_v0_0_2.wdl" as T2 workflow testTwoToolsWithSameId { input { String inp } call T.TestTranslationtool as stp1 { input: testtool=inp } call T2.TestTranslationtool as stp2 { input: testtool=inp } }""" self.assertEqual(expected, wf_wdl.get_string())
def test_max_memory(self): tool = TestTool() resources = WdlTranslator.build_resources_input( tool.wrapped_in_wf(), {}, max_mem=1 ) self.assertEqual( 1, resources["TestTranslationtoolWf.testtranslationtool_runtime_memory"] )
def test_cores(self): tool = TestTool() resources = WdlTranslator.build_resources_input(tool.wrapped_in_wf(), {}, is_root=True) self.assertEqual( 2, resources["TestTranslationtoolWf.testtranslationtool_runtime_cpu"])
def test_switch(self): from janis_unix import Echo, Cat w = WorkflowBuilder("switchTest") w.input("inp", int, value=2) w.input("inp1", str, value="Hello") w.input("inp2", str, value="Hi there") w.conditional( "echoswitch", [ (w.inp > 1, Echo(inp=w.inp1)), (w.inp.equals(1), Echo(inp="tasy case")), Echo(inp=w.inp2), ], ) w.output("out", source=w.echoswitch) _, wdl_tools = WdlTranslator.translate_workflow(w) expected = """\ version development import "echo_v1_0_0.wdl" as E workflow echoswitch { input { Int cond_inp String switch_case_1_inp String? switch_case_2_inp = "tasy case" String switch_case_3_inp } if ((cond_inp > 1)) { call E.echo as switch_case_1 { input: inp=switch_case_1_inp } } if (((cond_inp == 1) && !((cond_inp > 1)))) { call E.echo as switch_case_2 { input: inp=select_first([switch_case_2_inp, "tasy case"]) } } if (!(((cond_inp > 1) || (cond_inp == 1)))) { call E.echo as switch_case_3 { input: inp=switch_case_3_inp } } output { File out = select_first([switch_case_1.out, switch_case_2.out, switch_case_3.out]) } }""" echoswitch = wdl_tools["echoswitch"].get_string() self.assertEqual(expected, echoswitch)
def test_1(self): tool = FilenameGeneratedTool() mapped = [ a.get_string() for a in WdlTranslator.build_command_from_inputs(tool.inputs()) ] self.assertEqual('~{select_first([generatedInp, "~{inp}"])}', mapped[0]) self.assertEqual( '~{select_first([generatedInpOptional, "~{if defined(inpOptional) then inpOptional else "generated"}"])}', mapped[1], ) self.assertEqual( '~{select_first([generatedFileInp, "~{basename(fileInp, ".txt")}.transformed.fnp"])}', mapped[2], ) self.assertEqual( '~{select_first([generatedFileInpOptional, "~{if defined(fileInpOptional) then basename(fileInpOptional, ".txt") else "generated"}.optional.txt"])}', mapped[3], )
class TestWdlTranslatorOverrides(unittest.TestCase): def setUp(self): self.translator = WdlTranslator() def test_stringify_workflow(self): wdlobj = wdlgen.Workflow("wid", version="development") self.assertEqual( "version development\n\n\n\nworkflow wid {\n\n\n\n}", self.translator.stringify_translated_workflow(wdlobj), ) def test_stringify_tool(self): wdlobj = wdlgen.Task("tid", version="development") self.assertEqual( "version development\n\ntask tid {\n\n\n\n\n}", self.translator.stringify_translated_tool(wdlobj), ) def test_stringify_inputs(self): d = {"wid.inp1": 1} self.assertEqual( '{\n "wid.inp1": 1\n}', self.translator.stringify_translated_inputs(d) ) def test_workflow_filename(self): w = WorkflowBuilder("wid") self.assertEqual("wid.wdl", self.translator.workflow_filename(w)) def test_tools_filename(self): self.assertEqual( "TestTranslationtool.wdl", self.translator.tool_filename(TestTool().id()) ) def test_inputs_filename(self): w = WorkflowBuilder("wid") self.assertEqual("wid-inp.json", self.translator.inputs_filename(w)) def test_resources_filename(self): w = WorkflowBuilder("wid") self.assertEqual("wid-resources.json", self.translator.resources_filename(w))
def test_inputs_generator_array_of_secondary_files(self): w = WorkflowBuilder("tst") w.input("wsec", Array(TestTypeWithSecondary()), default=["test.ext"]) inpsdict = WdlTranslator().build_inputs_file(w, merge_resources=False) self.assertListEqual(["test.ext"], inpsdict.get("tst.wsec")) self.assertListEqual(["test.txt"], inpsdict.get("tst.wsec_txt"))
def setUp(self): self.translator = WdlTranslator()
def test_environment1(self): t = WdlTranslator().translate_tool_internal(tool=TestTool()) s = t.get_string() print(s)