Skip to content

Commit

Permalink
tests: use pathlib.Path.same_file
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 8, 2021
1 parent 461623b commit 1350447
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ def test_meta():

ds = qpformat.load_data(path=tf, meta_data={"time": 47})
assert ds.get_time() == 47
assert tf in ds.get_name()
for pp in ds.get_name():
if pp.same_file(tf):
break
else:
assert False, "{} not in {}".format(tf, ds.get_name())

# cleanup
try:
Expand Down
16 changes: 12 additions & 4 deletions tests/test_series_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
datapath = pathlib.Path(__file__).parent / "data"


def assert_path_in_list(path, path_list):
for ff in path_list:
if path.same_file(ff):
break
else:
assert False, "{} not in {}".format(path, path_list)


def setup_folder_single_h5(size=2, tdir=None):
path = datapath / "single_qpimage.h5"
if tdir is None:
Expand Down Expand Up @@ -54,8 +62,8 @@ def test_load_data():
ds = qpformat.load_data(path)
# check files in folder
assert len(ds) == 2
for ff in ds.files:
assert ff in files
for f1 in ds.files:
assert_path_in_list(f1, files)
# names should be different
assert ds.get_name(0) != ds.get_name(1)
# data should be the same
Expand All @@ -81,7 +89,7 @@ def test_multiple_formats_phasics_tif():
path, files = setup_folder_single_phasics_tif()
ds = qpformat.load_data(path)
for ff in ds.files:
assert ff in files
assert_path_in_list(ff, files)
assert ds.verify(ds.path)
assert ds.__class__.__name__ == "SeriesFolder"
shutil.rmtree(path, ignore_errors=True)
Expand All @@ -96,7 +104,7 @@ def test_multiple_formats_phasics_tif_ignore_h5():
path, _files2 = setup_folder_single_h5(tdir=path)
ds = qpformat.load_data(path)
for ff in ds.files:
assert ff in files1
assert_path_in_list(ff, files1)
shutil.rmtree(path, ignore_errors=True)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_series_hdf5_qpimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_load_data():

ds = qpformat.load_data(tf)
assert len(ds) == 2
assert ds.path == pathlib.Path(tf)
assert ds.path.same_file(pathlib.Path(tf))
assert np.isnan(ds.get_time(1))
assert "SeriesHdf5Qpimage" in ds.__repr__()
qpd = ds.get_qpimage(1)
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_subjoined_load_data():

ds = qpformat.load_data(tf)
assert len(ds) == 2
assert ds.path == pathlib.Path(tf)
assert ds.path.same_file(pathlib.Path(tf))
assert np.isnan(ds.get_time(1))
assert "SeriesHdf5QpimageSubjoined" in ds.__repr__()
qpd = ds.get_qpimage(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_series_zip_tif_holo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_basic():
assert ds.storage_type == "hologram"
assert len(ds) == num
assert ds.is_series
assert ds.path == path
assert ds.path.same_file(path)
assert "SeriesZipTifHolo" in ds.__repr__()

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_single_npy_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_load_phase():

ds = qpformat.load_data(tf, as_type="float64")
assert np.allclose(ds.get_qpimage().pha, phase, atol=1e-15, rtol=0)
assert ds.path == tf
assert ds.path.same_file(tf)
assert "SingleNpyNumpy" in ds.__repr__()

try:
Expand Down

0 comments on commit 1350447

Please sign in to comment.