From c44aeb84c7709cbc3abe5581edcaa2c9bf8e0fad Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Mon, 17 Mar 2025 16:01:28 +0100 Subject: [PATCH 1/4] Exclude Java-related workaround from coverage --- src/imcflibs/pathtools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imcflibs/pathtools.py b/src/imcflibs/pathtools.py index dff92699..f29eb417 100644 --- a/src/imcflibs/pathtools.py +++ b/src/imcflibs/pathtools.py @@ -175,7 +175,7 @@ def jython_fiji_exists(path): """ try: return os.path.exists(path) - except java.lang.AbstractMethodError: + except java.lang.AbstractMethodError: # pragma: no cover return False From 607c29e613507a0f63b782c88aaf7b3f3406d173 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Mon, 17 Mar 2025 16:13:09 +0100 Subject: [PATCH 2/4] Add test_parse_path_with_prefix() --- tests/test_pathtools.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_pathtools.py b/tests/test_pathtools.py index b52db8e0..7be6b989 100644 --- a/tests/test_pathtools.py +++ b/tests/test_pathtools.py @@ -30,6 +30,19 @@ def test_parse_path(): assert path_to_dir["ext"] == "" +def test_parse_path_with_prefix(): + """Test parse_path with a prefix parameter.""" + exp_full = "/FOO/BAR/tmp/foo/file.suffix" + prefix = "/FOO/BAR/" + path = "/tmp/foo/file.suffix" + assert parse_path(path, prefix)["full"] == exp_full + + # test again without trailing / leading slashes: + prefix = "/FOO/BAR" + path = "tmp/foo/file.suffix" + assert parse_path(path, prefix)["full"] == exp_full + + def test_parse_path_windows(): """Test using a Windows-style path.""" path = r"C:\Foo\Bar" From 7a1d8de732db084491b318f5f2fb7d451d55a4f6 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Mon, 17 Mar 2025 18:01:52 +0100 Subject: [PATCH 3/4] Add test_gen_name_from_orig() --- tests/test_pathtools.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_pathtools.py b/tests/test_pathtools.py index 7be6b989..19acda57 100644 --- a/tests/test_pathtools.py +++ b/tests/test_pathtools.py @@ -4,6 +4,7 @@ from imcflibs.pathtools import parse_path from imcflibs.pathtools import jython_fiji_exists from imcflibs.pathtools import image_basename +from imcflibs.pathtools import gen_name_from_orig def test_parse_path(): @@ -94,3 +95,14 @@ def test_image_basename(): assert image_basename("/path/to/image_file_01.png") == "image_file_01" assert image_basename("more-complex-stack.ome.tif") == "more-complex-stack" assert image_basename("/tmp/FoObAr.OMe.tIf") == "FoObAr" + + +def test_gen_name_from_orig(): + """Test assembling an output name from input, tag and suffix.""" + outpath = "/outpath" + inpath = "/inpath/to/foobar.tif" + tag = "-avg" + suffix = ".h5" + generated = gen_name_from_orig(outpath, inpath, tag, suffix) + assert generated == "/outpath/foobar-avg.h5" + From f0fdf76584fc55616dce80b57b3ccdb6fe578204 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter Date: Mon, 17 Mar 2025 18:11:16 +0100 Subject: [PATCH 4/4] Add test_gen_name_from_orig() --- tests/test_pathtools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_pathtools.py b/tests/test_pathtools.py index 19acda57..2a0338e6 100644 --- a/tests/test_pathtools.py +++ b/tests/test_pathtools.py @@ -5,6 +5,7 @@ from imcflibs.pathtools import jython_fiji_exists from imcflibs.pathtools import image_basename from imcflibs.pathtools import gen_name_from_orig +from imcflibs.pathtools import derive_out_dir def test_parse_path(): @@ -106,3 +107,10 @@ def test_gen_name_from_orig(): generated = gen_name_from_orig(outpath, inpath, tag, suffix) assert generated == "/outpath/foobar-avg.h5" + +def test_derive_out_dir(): + """Test derive_out_dir() using various parameter combinations.""" + assert derive_out_dir("/foo", "-") == "/foo" + assert derive_out_dir("/foo", "none") == "/foo" + assert derive_out_dir("/foo", "NONE") == "/foo" + assert derive_out_dir("/foo", "/bar") == "/bar"