Skip to content

Commit 4e99762

Browse files
authored
Merge pull request #48 from imcf/test-pathtools
Add some pathtools tests
2 parents 7b9b579 + f0fdf76 commit 4e99762

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/imcflibs/pathtools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def jython_fiji_exists(path):
175175
"""
176176
try:
177177
return os.path.exists(path)
178-
except java.lang.AbstractMethodError:
178+
except java.lang.AbstractMethodError: # pragma: no cover
179179
return False
180180

181181

tests/test_pathtools.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from imcflibs.pathtools import parse_path
55
from imcflibs.pathtools import jython_fiji_exists
66
from imcflibs.pathtools import image_basename
7+
from imcflibs.pathtools import gen_name_from_orig
8+
from imcflibs.pathtools import derive_out_dir
79

810

911
def test_parse_path():
@@ -30,6 +32,19 @@ def test_parse_path():
3032
assert path_to_dir["ext"] == ""
3133

3234

35+
def test_parse_path_with_prefix():
36+
"""Test parse_path with a prefix parameter."""
37+
exp_full = "/FOO/BAR/tmp/foo/file.suffix"
38+
prefix = "/FOO/BAR/"
39+
path = "/tmp/foo/file.suffix"
40+
assert parse_path(path, prefix)["full"] == exp_full
41+
42+
# test again without trailing / leading slashes:
43+
prefix = "/FOO/BAR"
44+
path = "tmp/foo/file.suffix"
45+
assert parse_path(path, prefix)["full"] == exp_full
46+
47+
3348
def test_parse_path_windows():
3449
"""Test using a Windows-style path."""
3550
path = r"C:\Foo\Bar"
@@ -81,3 +96,21 @@ def test_image_basename():
8196
assert image_basename("/path/to/image_file_01.png") == "image_file_01"
8297
assert image_basename("more-complex-stack.ome.tif") == "more-complex-stack"
8398
assert image_basename("/tmp/FoObAr.OMe.tIf") == "FoObAr"
99+
100+
101+
def test_gen_name_from_orig():
102+
"""Test assembling an output name from input, tag and suffix."""
103+
outpath = "/outpath"
104+
inpath = "/inpath/to/foobar.tif"
105+
tag = "-avg"
106+
suffix = ".h5"
107+
generated = gen_name_from_orig(outpath, inpath, tag, suffix)
108+
assert generated == "/outpath/foobar-avg.h5"
109+
110+
111+
def test_derive_out_dir():
112+
"""Test derive_out_dir() using various parameter combinations."""
113+
assert derive_out_dir("/foo", "-") == "/foo"
114+
assert derive_out_dir("/foo", "none") == "/foo"
115+
assert derive_out_dir("/foo", "NONE") == "/foo"
116+
assert derive_out_dir("/foo", "/bar") == "/bar"

0 commit comments

Comments
 (0)