From c0815edaa903f8f198839733ca22f112b7dde82d Mon Sep 17 00:00:00 2001 From: Camilo Velez Date: Wed, 24 Jan 2024 13:47:30 -0500 Subject: [PATCH 1/4] test(pythonapi): add initial tests --- tests/resources/assembler.cwl | 41 +++ tests/resources/basicfl.cwl | 41 +++ tests/resources/filerenaming.cwl | 41 +++ tests/resources/filerenaming_io.yml | 3 + tests/resources/montage.cwl | 44 +++ tests/resources/omeconverter.cwl | 32 ++ tests/test_pythonapi.py | 469 ++++++++++++++++++++++++++++ 7 files changed, 671 insertions(+) create mode 100644 tests/resources/assembler.cwl create mode 100644 tests/resources/basicfl.cwl create mode 100644 tests/resources/filerenaming.cwl create mode 100644 tests/resources/filerenaming_io.yml create mode 100644 tests/resources/montage.cwl create mode 100644 tests/resources/omeconverter.cwl create mode 100644 tests/test_pythonapi.py diff --git a/tests/resources/assembler.cwl b/tests/resources/assembler.cwl new file mode 100644 index 00000000..e9a9c22b --- /dev/null +++ b/tests/resources/assembler.cwl @@ -0,0 +1,41 @@ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.2 +class: CommandLineTool + +requirements: + DockerRequirement: + dockerPull: polusai/image-assembler-plugin:1.2.1-dev0 + InitialWorkDirRequirement: + listing: + - writable: true + entry: $(inputs.outDir) + InlineJavascriptRequirement: {} + +inputs: + imgPath: + type: Directory + inputBinding: + prefix: --imgPath + outDir: + type: Directory + inputBinding: + prefix: --outDir + preview: + type: boolean? + inputBinding: + prefix: --preview + stitchPath: + type: Directory + inputBinding: + prefix: --stitchPath + timesliceNaming: + type: boolean? + inputBinding: + prefix: --timesliceNaming + +outputs: + outDir: + type: Directory + outputBinding: + glob: $(inputs.outDir.basename) diff --git a/tests/resources/basicfl.cwl b/tests/resources/basicfl.cwl new file mode 100644 index 00000000..1306896f --- /dev/null +++ b/tests/resources/basicfl.cwl @@ -0,0 +1,41 @@ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.0 +class: CommandLineTool + +requirements: + DockerRequirement: + dockerPull: polusai/basic-flatfield-estimation-plugin:2.1.0 + InitialWorkDirRequirement: + listing: + - writable: true + entry: $(inputs.outDir) + InlineJavascriptRequirement: {} + +inputs: + filePattern: + type: string + inputBinding: + prefix: --filePattern + getDarkfield: + type: boolean + inputBinding: + prefix: --getDarkfield + groupBy: + type: string? + inputBinding: + prefix: --groupBy + inpDir: + type: Directory + inputBinding: + prefix: --inpDir + outDir: + type: Directory + inputBinding: + prefix: --outDir + +outputs: + outDir: + type: Directory + outputBinding: + glob: $(inputs.outDir.basename) diff --git a/tests/resources/filerenaming.cwl b/tests/resources/filerenaming.cwl new file mode 100644 index 00000000..b1992db4 --- /dev/null +++ b/tests/resources/filerenaming.cwl @@ -0,0 +1,41 @@ +#!/usr/bin/env cwl-runner + +cwlVersion: v1.1 +class: CommandLineTool + +requirements: + DockerRequirement: + dockerPull: polusai/file-renaming-plugin:0.2.0 + InitialWorkDirRequirement: + listing: + - writable: true + entry: $(inputs.outDir) + InlineJavascriptRequirement: {} + +inputs: + filePattern: + type: string + inputBinding: + prefix: --filePattern + inpDir: + type: Directory + inputBinding: + prefix: --inpDir + mapDirectory: + type: string? + inputBinding: + prefix: --mapDirectory + outDir: + type: Directory + inputBinding: + prefix: --outDir + outFilePattern: + type: string + inputBinding: + prefix: --outFilePattern + +outputs: + outDir: + type: Directory + outputBinding: + glob: $(inputs.outDir.basename) diff --git a/tests/resources/filerenaming_io.yml b/tests/resources/filerenaming_io.yml new file mode 100644 index 00000000..e90e971b --- /dev/null +++ b/tests/resources/filerenaming_io.yml @@ -0,0 +1,3 @@ +filePattern: .*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif +mapDirectory: raw +outFilePattern: x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif diff --git a/tests/resources/montage.cwl b/tests/resources/montage.cwl new file mode 100644 index 00000000..495a59e7 --- /dev/null +++ b/tests/resources/montage.cwl @@ -0,0 +1,44 @@ +class: CommandLineTool +cwlVersion: v1.2 +inputs: + filePattern: + inputBinding: + prefix: --filePattern + type: string + flipAxis: + inputBinding: + prefix: --flipAxis + type: string? + gridSpacing: + inputBinding: + prefix: --gridSpacing + type: string? + imageSpacing: + inputBinding: + prefix: --imageSpacing + type: string? + inpDir: + inputBinding: + prefix: --inpDir + type: Directory + layout: + inputBinding: + prefix: --layout + type: string? + outDir: + inputBinding: + prefix: --outDir + type: Directory +outputs: + outDir: + outputBinding: + glob: $(inputs.outDir.basename) + type: Directory +requirements: + DockerRequirement: + dockerPull: polusai/montage-plugin:0.5.0 + InitialWorkDirRequirement: + listing: + - entry: $(inputs.outDir) + writable: true + InlineJavascriptRequirement: {} diff --git a/tests/resources/omeconverter.cwl b/tests/resources/omeconverter.cwl new file mode 100644 index 00000000..322dfb09 --- /dev/null +++ b/tests/resources/omeconverter.cwl @@ -0,0 +1,32 @@ +class: CommandLineTool +cwlVersion: v1.2 +inputs: + fileExtension: + inputBinding: + prefix: --fileExtension + type: string + filePattern: + inputBinding: + prefix: --filePattern + type: string + inpDir: + inputBinding: + prefix: --inpDir + type: Directory + outDir: + inputBinding: + prefix: --outDir + type: Directory +outputs: + outDir: + outputBinding: + glob: $(inputs.outDir.basename) + type: Directory +requirements: + DockerRequirement: + dockerPull: polusai/ome-converter-plugin:0.3.0 + InitialWorkDirRequirement: + listing: + - entry: $(inputs.outDir) + writable: true + InlineJavascriptRequirement: {} diff --git a/tests/test_pythonapi.py b/tests/test_pythonapi.py new file mode 100644 index 00000000..01a346fa --- /dev/null +++ b/tests/test_pythonapi.py @@ -0,0 +1,469 @@ +# pylint: disable=W0621, W0212 +from pathlib import Path +from typing import Any + +import cwl_utils.parser as cu_parser +import hypothesis +import pytest +import yaml + +from wic.api import Step, Workflow +from wic.api._types import CWL_TYPES_DICT +from wic.api.pythonapi import ( + _WIC_PATH, + CLTInput, + InvalidStepError, + MissingRequiredValueError, +) + +RSRC_DIR = Path(__file__).parent / "resources" + + +@pytest.fixture +def assembler_step() -> Step: + """Assembler Step.""" + assembler_ = RSRC_DIR / "assembler.cwl" + return Step(assembler_) + + +@pytest.fixture +def renaming_step() -> Step: + """Renaming Step.""" + renaming_ = RSRC_DIR / "filerenaming.cwl" + return Step(renaming_) + + +@pytest.fixture +def basic_step() -> Step: + """Basic Step.""" + basic_ = RSRC_DIR / "basicfl.cwl" + return Step(basic_) + + +@pytest.fixture +def montage_step() -> Step: + """Basic Step.""" + montage_ = RSRC_DIR / "montage.cwl" + return Step(montage_) + + +@pytest.fixture +def omeconverter_step() -> Step: + """Basic Step.""" + omeconverter_ = RSRC_DIR / "omeconverter.cwl" + return Step(omeconverter_) + + +@pytest.fixture(scope="session") +def basic_step_session() -> Step: + """Basic Step.""" + basic_ = RSRC_DIR / "basicfl.cwl" + return Step(basic_) + + +@pytest.fixture +def steps(assembler_step: Step, renaming_step: Step, basic_step: Step) -> list[Step]: + """Return list of steps.""" + return [assembler_step, renaming_step, basic_step] + + +@pytest.fixture +def assembler_cwl() -> Any: + """Assembler CWL.""" + assembler_ = RSRC_DIR / "assembler.cwl" + return cu_parser.load_document_by_uri(assembler_) + + +@pytest.fixture(scope="session") +def cwl_adapters(tmp_path_factory: Path) -> Path: + """CWL Adapters Tmp Dir.""" + tmp = tmp_path_factory.mktemp("tmp") # type: ignore + return tmp # type: ignore + + +def test_cltinp_type(assembler_cwl: Any) -> None: + """Test CLTInput type.""" + for inp in assembler_cwl.inputs: + clt_inp = CLTInput(inp) + assert isinstance(clt_inp.inp_type, object) + # set type_ variable used for comparison + if hasattr(inp, "type_"): + if isinstance(inp.type_, list): # optional (null, boolean) + type_ = inp.type_[1] + else: + type_ = inp.type_ + elif hasattr(inp, "type"): + if isinstance(inp.type, list): # optional (null, boolean) + type_ = inp.type[1] + else: + type_ = inp.type + assert clt_inp.inp_type == CWL_TYPES_DICT[type_] + + +def test_step1(assembler_step: Step) -> None: + """Test Step 1.""" + st = assembler_step + assert isinstance(st, Step) + assert st.clt_name == "assembler" + assert all(isinstance(i, CLTInput) for i in st.inputs) + with RSRC_DIR.joinpath("assembler.cwl").open("r", encoding="utf-8") as file: + assert st.yaml == yaml.safe_load(file) + assert st.cwl_version == "v1.2" + assert st.clt_path == RSRC_DIR / "assembler.cwl" + + +def test_step1_cwl(assembler_step: Step, assembler_cwl: Any) -> None: + """Test Step 1.""" + st = assembler_step + cwl_ = assembler_cwl + assert st.clt == cwl_ + + +def test_step1_str() -> None: + """Test Step 1 with str.""" + st = Step(str(RSRC_DIR / "assembler.cwl")) + assert isinstance(st, Step) + assert st.clt_name == "assembler" + assert all(isinstance(i, CLTInput) for i in st.inputs) + with RSRC_DIR.joinpath("assembler.cwl").open("r", encoding="utf-8") as file: + assert st.yaml == yaml.safe_load(file) + assert st.cwl_version == "v1.2" + assert st.clt_path == RSRC_DIR / "assembler.cwl" + + +def test_step2(renaming_step: Step) -> None: + """Test Step 2.""" + st = renaming_step + assert isinstance(st, Step) + assert st.clt_name == "filerenaming" + assert all(isinstance(i, CLTInput) for i in st.inputs) + with RSRC_DIR.joinpath("filerenaming.cwl").open("r", encoding="utf-8") as file: + assert st.yaml == yaml.safe_load(file) + assert st.cwl_version == "v1.1" + assert st.clt_path == RSRC_DIR / "filerenaming.cwl" + + +def test_step3(basic_step: Step) -> None: + """Test Step 3.""" + st = basic_step + assert isinstance(st, Step) + assert st.clt_name == "basicfl" + assert all(isinstance(i, CLTInput) for i in st.inputs) + with RSRC_DIR.joinpath("basicfl.cwl").open("r", encoding="utf-8") as file: + assert st.yaml == yaml.safe_load(file) + assert st.cwl_version == "v1.0" + assert st.clt_path == RSRC_DIR / "basicfl.cwl" + + +def test_cfg_yml1(renaming_step: Step) -> None: + """Test IO cfg yaml 1.""" + st1 = renaming_step + st2 = Step(RSRC_DIR / "filerenaming.cwl", RSRC_DIR / "filerenaming_io.yml") + with RSRC_DIR.joinpath("filerenaming_io.yml").open("r", encoding="utf-8") as file: + assert st2.cfg_yaml == yaml.safe_load(file) + assert st1.clt_name == st2.clt_name + assert all(isinstance(i, CLTInput) for i in st2.inputs) + assert [x for x in st2.inputs if x.name == + "outFilePattern"][0].value == "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + assert [x for x in st2.inputs if x.name == + "filePattern"][0].value == ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + assert [x for x in st2.inputs if x.name == "mapDirectory"][0].value == "raw" + assert st2.cwl_version == "v1.1" + + +def test_cfg_yml1_str(renaming_step: Step) -> None: + """Test IO cfg yaml 1 with str.""" + st1 = renaming_step + st2 = Step(RSRC_DIR / "filerenaming.cwl", str(RSRC_DIR / "filerenaming_io.yml")) + with RSRC_DIR.joinpath("filerenaming_io.yml").open("r", encoding="utf-8") as file: + assert st2.cfg_yaml == yaml.safe_load(file) + assert st1.clt_name == st2.clt_name + assert all(isinstance(i, CLTInput) for i in st2.inputs) + assert [x for x in st2.inputs if x.name == + "outFilePattern"][0].value == "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + assert [x for x in st2.inputs if x.name == + "filePattern"][0].value == ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + assert [x for x in st2.inputs if x.name == "mapDirectory"][0].value == "raw" + assert st2.cwl_version == "v1.1" + + +def test_cfg_yml2() -> None: + """Test IO cfg yaml 2.""" + st = Step(RSRC_DIR / "filerenaming.cwl", RSRC_DIR / "filerenaming_io.yml") + assert st.clt_path == RSRC_DIR / "filerenaming.cwl" + + +def test_set_inp1(assembler_step: Step) -> None: + """Test set input 1.""" + st = assembler_step + st.imgPath = RSRC_DIR + with pytest.raises(TypeError): + st.outDir = str(RSRC_DIR / "out") + with pytest.raises(TypeError, match="got str, expected Path"): + st.outDir = str(RSRC_DIR / "out") + st.outDir = RSRC_DIR / "out" + st.preview = True + st.timesliceNaming = False + assert st.imgPath.value == RSRC_DIR # type: ignore + assert st.outDir.value == RSRC_DIR / "out" # type: ignore + + +def test_set_inp2(assembler_step: Step) -> None: + """Test set input 2.""" + st = assembler_step + st.imgPath = RSRC_DIR + st.outDir = RSRC_DIR / "out" + st.preview = True + st.timesliceNaming = False + wic_yaml = { + "assembler": { + "in": { + "imgPath": str(RSRC_DIR), + "outDir": str(RSRC_DIR / "out"), + "preview": True, + "timesliceNaming": False + } + } + } + assert st._yml == wic_yaml + + +@hypothesis.given( + filePattern=hypothesis.strategies.text(min_size=8), + darkfield=hypothesis.strategies.booleans(), + groupby=hypothesis.strategies.text(min_size=3) +) +def test_set_inp3(basic_step_session: Step, + filePattern: str, + darkfield: bool, + groupby: str) -> None: + """Test set input 3.""" + st = basic_step_session + st.filePattern = filePattern + st.getDarkfield = darkfield + st.groupBy = groupby + assert st.filePattern.value == filePattern # type: ignore + assert st.getDarkfield.value == darkfield # type: ignore + assert st.groupBy.value == groupby # type: ignore + + +def test_link_inp1(assembler_step: Step, + renaming_step: Step) -> None: + """Test link inputs 1.""" + renaming_step.inpDir = assembler_step.outDir + inpDir = renaming_step.inpDir.value.split("*")[1] + outDir = assembler_step.outDir.value.split("&")[1] + assert inpDir == outDir + + +def test_link_inp2(assembler_step: Step, + basic_step: Step) -> None: + """Test link inputs 2.""" + assembler_step.imgPath = basic_step.outDir + imgPath = assembler_step.imgPath.value.split("*")[1] + outDir = basic_step.outDir.value.split("&")[1] + assert imgPath == outDir + + +def test_link_inp3(assembler_step: Step, + renaming_step: Step, + basic_step: Step) -> None: + """Test link inputs if already linked 1.""" + assembler_step.imgPath = basic_step.outDir + renaming_step.inpDir = basic_step.outDir + imgPath = assembler_step.imgPath.value.split("*")[1] + outDir = basic_step.outDir.value.split("&")[1] + inpDir = renaming_step.inpDir.value.split("*")[1] + assert len(set([imgPath, outDir, inpDir])) == 1 + + +def test_link_inp4(assembler_step: Step, + renaming_step: Step, + basic_step: Step) -> None: + """Test link inputs if already linked 2.""" + basic_step.inpDir = renaming_step.outDir + assembler_step.imgPath = basic_step.outDir + assembler_step.stitchPath = basic_step.outDir + imgPath = assembler_step.imgPath.value.split("*")[1] + stitchPath = assembler_step.stitchPath.value.split("*")[1] + inpDir = basic_step.inpDir.value.split("*")[1] + outDir_basic = basic_step.outDir.value.split("&")[1] + outDir_renaming = renaming_step.outDir.value.split("&")[1] + assert imgPath == outDir_basic + assert imgPath == stitchPath + assert inpDir == outDir_renaming + + +def test_inp_names1(assembler_step: Step) -> None: + """Test input names 1.""" + st = assembler_step + assert sorted(st._input_names) == ["imgPath", "outDir", "preview", "stitchPath", "timesliceNaming"] + + +def test_inp_names2(renaming_step: Step) -> None: + """Test input names 2.""" + st = renaming_step + assert sorted(st._input_names) == ["filePattern", "inpDir", "mapDirectory", "outDir", "outFilePattern"] + + +def test_inp_names3(basic_step: Step) -> None: + """Test input names 3.""" + st = basic_step + assert sorted(st._input_names) == ["filePattern", "getDarkfield", "groupBy", "inpDir", "outDir"] + + +@pytest.mark.parametrize("step_index", range(3)) +def test_save_cwl(steps: list[Step], step_index: int, cwl_adapters: Path) -> None: + """Test save yaml 1.""" + st = steps[step_index] + if st.clt_name == "assembler": + st.imgPath = RSRC_DIR + st.preview = True + st.timesliceNaming = False + if st.clt_name == "filerenaming": + st.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + st.outFilePattern = "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + st.mapDirectory = "raw" + st.inpDir = RSRC_DIR + if st.clt_name == "basicfl": + st.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + st.getDarkfield = False + st.groupBy = "channel" + st.inpDir = RSRC_DIR + st.outDir = RSRC_DIR / "out" + with RSRC_DIR.joinpath("assembler.cwl").open("r", encoding="utf-8") as file: + cwl_ = yaml.safe_load(file) + st._save_cwl(cwl_adapters) + with (cwl_adapters / "cwl_adapters" / "assembler.cwl").open("r", encoding="utf-8") as file: + assert yaml.safe_load(file) == cwl_ + + +def test_validate1(assembler_step: Step, tmp_path: Path) -> None: + """Test validate 1.""" + st = assembler_step + st.imgPath = tmp_path + st.outDir = tmp_path / "out" + st.stitchPath = tmp_path / "stitch" + st._validate() + + +def test_validate2(assembler_step: Step, tmp_path: Path) -> None: + """Test validate 2.""" + st = assembler_step + st.imgPath = tmp_path + st.stitchPath = tmp_path / "stitch" + with pytest.raises(MissingRequiredValueError): + st._validate() + + +def test_wf1(basic_step: Step, + assembler_step: Step, + renaming_step: Step, + tmp_path: Path) -> None: + """Test WF1""" + wf_path = tmp_path.joinpath("wf") + with pytest.raises(InvalidStepError): + Workflow([basic_step, assembler_step, renaming_step], + name="wf1", _path=wf_path) + + +def test_wf2(basic_step: Step, + assembler_step: Step, + renaming_step: Step, + tmp_path: Path) -> None: + """Test WF2""" + wf_path = tmp_path.joinpath("wf") + basic_step.inpDir = tmp_path / "in" + basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + basic_step.getDarkfield = False + assembler_step.imgPath = basic_step.outDir + assembler_step.stitchPath = tmp_path / "stitch" + renaming_step.inpDir = assembler_step.outDir + with pytest.raises(InvalidStepError): + Workflow([basic_step, assembler_step, renaming_step], + name="wf1", _path=wf_path) + + +def test_wf3(basic_step: Step, + assembler_step: Step, + renaming_step: Step, + tmp_path: Path) -> None: + """Test WF3""" + wf_path = tmp_path.joinpath("wf") + basic_step.inpDir = tmp_path / "in" + basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + basic_step.getDarkfield = False + assembler_step.imgPath = basic_step.outDir + assembler_step.stitchPath = tmp_path / "stitch" + renaming_step.inpDir = assembler_step.outDir + renaming_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + renaming_step.outFilePattern = "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + renaming_step.outDir = tmp_path / "out" + wf = Workflow([basic_step, assembler_step, renaming_step], + name="wf1", _path=wf_path) + assert wf.name == "wf1" + # assert wf._path == wf_path + + +def test_wf4(basic_step: Step, + assembler_step: Step, + renaming_step: Step, + tmp_path: Path) -> None: + """Test WF4""" + wf_path = tmp_path.joinpath("wf") + basic_step.inpDir = tmp_path / "in" + basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + basic_step.getDarkfield = False + assembler_step.imgPath = basic_step.outDir + # assembler_step.stitchPath = tmp_path / "stitch" + renaming_step.inpDir = assembler_step.outDir + renaming_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + renaming_step.outFilePattern = "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + renaming_step.outDir = tmp_path / "out" + with pytest.raises(InvalidStepError): + Workflow([basic_step, assembler_step, renaming_step], + name="wf1", _path=wf_path) + + +def test_compile_1(basic_step: Step, + assembler_step: Step, + renaming_step: Step, + tmp_path: Path) -> None: + """Test Compile 1.""" + basic_step.inpDir = tmp_path / "in" + basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + basic_step.getDarkfield = False + assembler_step.imgPath = basic_step.outDir + assembler_step.stitchPath = tmp_path / "stitch" + renaming_step.inpDir = assembler_step.outDir + renaming_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + renaming_step.outFilePattern = "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" + renaming_step.outDir = tmp_path / "out" + wf = Workflow([basic_step, assembler_step, renaming_step], + name="wf1") + + compiled = wf.compile() + assert wf.yml_path == _WIC_PATH.joinpath("wf1.yml") + assert _WIC_PATH.joinpath("autogenerated/wf1.cwl") == compiled + assert compiled.exists() + + +def test_compile_2(omeconverter_step: Step, + montage_step: Step, + tmp_path: Path) -> None: + """Test Compile 2 with new Steps.""" + ome_converter = omeconverter_step + montage = montage_step + ome_converter.inpDir = tmp_path / "in" + ome_converter.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + ome_converter.fileExtension = "default" + montage.inpDir = ome_converter.outDir + montage.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" + montage.outDir = tmp_path / "out" + wf = Workflow([ome_converter, montage], + name="wf2") + + compiled = wf.compile() + assert wf.yml_path == _WIC_PATH.joinpath("wf2.yml") + assert _WIC_PATH.joinpath("autogenerated/wf2.cwl") == compiled + assert compiled.exists() From 35c766c8e2f101157b9943502b003be1578c2524 Mon Sep 17 00:00:00 2001 From: Camilo Velez Date: Wed, 24 Jan 2024 15:39:27 -0500 Subject: [PATCH 2/4] test(pythonapi): clean test pythonapi --- tests/test_pythonapi.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/test_pythonapi.py b/tests/test_pythonapi.py index 01a346fa..aff469af 100644 --- a/tests/test_pythonapi.py +++ b/tests/test_pythonapi.py @@ -359,12 +359,11 @@ def test_validate2(assembler_step: Step, tmp_path: Path) -> None: def test_wf1(basic_step: Step, assembler_step: Step, renaming_step: Step, - tmp_path: Path) -> None: + ) -> None: """Test WF1""" - wf_path = tmp_path.joinpath("wf") with pytest.raises(InvalidStepError): Workflow([basic_step, assembler_step, renaming_step], - name="wf1", _path=wf_path) + name="wf1") def test_wf2(basic_step: Step, @@ -372,7 +371,6 @@ def test_wf2(basic_step: Step, renaming_step: Step, tmp_path: Path) -> None: """Test WF2""" - wf_path = tmp_path.joinpath("wf") basic_step.inpDir = tmp_path / "in" basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" basic_step.getDarkfield = False @@ -381,7 +379,7 @@ def test_wf2(basic_step: Step, renaming_step.inpDir = assembler_step.outDir with pytest.raises(InvalidStepError): Workflow([basic_step, assembler_step, renaming_step], - name="wf1", _path=wf_path) + name="wf1") def test_wf3(basic_step: Step, @@ -389,7 +387,6 @@ def test_wf3(basic_step: Step, renaming_step: Step, tmp_path: Path) -> None: """Test WF3""" - wf_path = tmp_path.joinpath("wf") basic_step.inpDir = tmp_path / "in" basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" basic_step.getDarkfield = False @@ -400,9 +397,8 @@ def test_wf3(basic_step: Step, renaming_step.outFilePattern = "x{row:dd}_y{col:dd}_p{s:dd}_c{channel:d}.ome.tif" renaming_step.outDir = tmp_path / "out" wf = Workflow([basic_step, assembler_step, renaming_step], - name="wf1", _path=wf_path) + name="wf1") assert wf.name == "wf1" - # assert wf._path == wf_path def test_wf4(basic_step: Step, @@ -410,7 +406,6 @@ def test_wf4(basic_step: Step, renaming_step: Step, tmp_path: Path) -> None: """Test WF4""" - wf_path = tmp_path.joinpath("wf") basic_step.inpDir = tmp_path / "in" basic_step.filePattern = ".*_{row:c}{col:dd}_s{s:d}_w{channel:d}.*.ome.tif" basic_step.getDarkfield = False @@ -422,7 +417,7 @@ def test_wf4(basic_step: Step, renaming_step.outDir = tmp_path / "out" with pytest.raises(InvalidStepError): Workflow([basic_step, assembler_step, renaming_step], - name="wf1", _path=wf_path) + name="wf1") def test_compile_1(basic_step: Step, From 6c722306f0d264a4675137c8799934d673336c1b Mon Sep 17 00:00:00 2001 From: Camilo Velez Date: Wed, 24 Jan 2024 15:53:40 -0500 Subject: [PATCH 3/4] fix(pythonapi): fix problematic Path obj in tests --- tests/test_pythonapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pythonapi.py b/tests/test_pythonapi.py index aff469af..a4aa685e 100644 --- a/tests/test_pythonapi.py +++ b/tests/test_pythonapi.py @@ -174,7 +174,7 @@ def test_cfg_yml1(renaming_step: Step) -> None: def test_cfg_yml1_str(renaming_step: Step) -> None: """Test IO cfg yaml 1 with str.""" st1 = renaming_step - st2 = Step(RSRC_DIR / "filerenaming.cwl", str(RSRC_DIR / "filerenaming_io.yml")) + st2 = Step(RSRC_DIR.joinpath("filerenaming.cwl"), str(RSRC_DIR / "filerenaming_io.yml")) with RSRC_DIR.joinpath("filerenaming_io.yml").open("r", encoding="utf-8") as file: assert st2.cfg_yaml == yaml.safe_load(file) assert st1.clt_name == st2.clt_name From a63d34a4ee05bbae4e48c0fdea5a9302113cf221 Mon Sep 17 00:00:00 2001 From: Camilo Velez Date: Thu, 25 Jan 2024 09:02:13 -0500 Subject: [PATCH 4/4] test(pythonapi): add type ignore to cfg yml --- tests/test_pythonapi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_pythonapi.py b/tests/test_pythonapi.py index a4aa685e..634e7ffa 100644 --- a/tests/test_pythonapi.py +++ b/tests/test_pythonapi.py @@ -174,7 +174,8 @@ def test_cfg_yml1(renaming_step: Step) -> None: def test_cfg_yml1_str(renaming_step: Step) -> None: """Test IO cfg yaml 1 with str.""" st1 = renaming_step - st2 = Step(RSRC_DIR.joinpath("filerenaming.cwl"), str(RSRC_DIR / "filerenaming_io.yml")) + # mypy incorrectly complains about the type of the args + st2 = Step(RSRC_DIR.joinpath("filerenaming.cwl"), str(RSRC_DIR / "filerenaming_io.yml")) # type: ignore with RSRC_DIR.joinpath("filerenaming_io.yml").open("r", encoding="utf-8") as file: assert st2.cfg_yaml == yaml.safe_load(file) assert st1.clt_name == st2.clt_name