Skip to content

Commit e34638e

Browse files
committed
tests: change copy of example to temp folder & not using logic in test
1 parent 709b48c commit e34638e

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

tests/cwd/example.tiff

-64.2 KB
Binary file not shown.

tests/home/example.tiff

-64.2 KB
Binary file not shown.

tests/test/example.tiff

-64.2 KB
Binary file not shown.

tests/test_loadimage.py renamed to tests/test_load_image.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,14 @@
2626

2727
@pytest.mark.parametrize("input_path, expected", load_image_param)
2828
def test_load_image_cases(input_path, expected, user_filesystem):
29-
base_dir, home_dir, cwd_dir, test_dir = user_filesystem
30-
test_file_dir = Path(__file__).parent
31-
cwd_dir = test_file_dir / "cwd"
32-
home_dir = test_file_dir / "home"
33-
test_dir = test_file_dir / "test"
34-
src_image = test_file_dir.parent / "docs/examples/example.tiff"
29+
home_dir = user_filesystem["home"]
30+
cwd_dir = user_filesystem["cwd"]
31+
os.chdir(cwd_dir)
3532

36-
# Copy test image into all directories
37-
for dir in [cwd_dir, home_dir, test_dir]:
38-
dst = Path(dir) / "example.tiff"
39-
dst.parent.mkdir(parents=True, exist_ok=True)
40-
shutil.copy(src_image, dst)
33+
# locate source example file inside project docs
34+
source_file = PROJECT_ROOT / "docs" / "examples" / "example.tiff"
35+
shutil.copy(source_file, cwd_dir / "example.tiff")
36+
shutil.copy(source_file, home_dir / "example.tiff")
4137

4238
old_cwd = Path.cwd()
4339
os.chdir(home_dir)
@@ -47,18 +43,13 @@ def test_load_image_cases(input_path, expected, user_filesystem):
4743
"Cfg", (), {"fliphorizontal": True, "flipvertical": False}
4844
)()
4945
loader = LoadImage(cfg)
50-
51-
if expected:
52-
# Handle case 1-3 for absolute, cwd, and home directory.
53-
actual = loader.loadImage(input_path)
54-
assert isinstance(actual, np.ndarray)
55-
else:
56-
# Handle Case 4 for missing file.
57-
with pytest.raises(
58-
FileNotFoundError,
59-
match=r"file not found: .*"
60-
r"Please rerun specifying a valid filename\.",
61-
):
62-
loader.loadImage(input_path)
46+
actual = loader.loadImage(input_path)
47+
assert isinstance(actual, np.ndarray)
48+
except FileNotFoundError:
49+
pytest.raises(
50+
FileNotFoundError,
51+
match=r"file not found:"
52+
r" .*Please rerun specifying a valid filename\.",
53+
)
6354
finally:
6455
os.chdir(old_cwd)

0 commit comments

Comments
 (0)