Skip to content

Commit

Permalink
tests: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jun 15, 2018
1 parent 090ab9c commit 1e8f4f5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
description=description,
long_description=open('README.rst').read() if exists('README.rst') else '',
install_requires=["nrefocus>=0.1.5",
"numpy>=1.9.0",
"numpy>=1.12.0",
"qpimage",
"scikit-image>=0.11.0",
"scipy>=0.18.0",
Expand Down
26 changes: 12 additions & 14 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os
from os.path import abspath, dirname, join
import sys
import pathlib
import shutil
import tempfile

import numpy as np

# Add parent directory to beginning of path variable
sys.path.insert(0, dirname(dirname(abspath(__file__))))
import qpformat.core # noqa: E402
import qpformat.core


def test_meta():
Expand Down Expand Up @@ -94,28 +92,25 @@ def test_set_bg():


def test_set_bg_series():
# data
data_dir = tempfile.mkdtemp(prefix="qpformat_test_data_")
data_dir = pathlib.Path(data_dir)

data1 = np.ones((20, 20), dtype=float)
data1 *= np.linspace(-.1, 3, 20).reshape(-1, 1)
f_data1 = join(data_dir, "data1.npy")
np.save(f_data1, data1)
np.save(data_dir / "data1.npy", data1)

data2 = data1 * np.linspace(1.33, 1.04, 20).reshape(1, -1)
f_data2 = join(data_dir, "data2.npy")
np.save(f_data2, data2)
np.save(data_dir / "data2.npy", data2)

# bg data
bg_data_dir = tempfile.mkdtemp(prefix="qpformat_test_bg_data_")
bg_data_dir = pathlib.Path(bg_data_dir)

bg_data1 = data1 * np.linspace(1.0, 1.02, 20).reshape(1, -1)
f_bg_data1 = join(bg_data_dir, "bg_data1.npy")
np.save(f_bg_data1, bg_data1)
np.save(bg_data_dir / "bg_data1.npy", bg_data1)

bg_data2 = data1 * np.linspace(.9, 0.87, 20).reshape(-1, 1)
f_bg_data2 = join(bg_data_dir, "bg_data2.npy")
np.save(f_bg_data2, bg_data2)
np.save(bg_data_dir / "bg_data2.npy", bg_data2)

# tests
ds1 = qpformat.core.load_data(path=data_dir, as_type="float64")
Expand All @@ -127,6 +122,9 @@ def test_set_bg_series():
assert np.allclose(ds1.get_qpimage(1).pha, data2 - bg_data2)
assert not np.allclose(ds1.get_qpimage(0).pha, data2 - bg_data2)

shutil.rmtree(str(data_dir), ignore_errors=True)
shutil.rmtree(str(bg_data_dir), ignore_errors=True)


if __name__ == "__main__":
# Run all tests
Expand Down
17 changes: 12 additions & 5 deletions tests/test_single_npy_numpy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from os.path import abspath, dirname
import sys
import os
import tempfile

import numpy as np

# Add parent directory to beginning of path variable
sys.path.insert(0, dirname(dirname(abspath(__file__))))
import qpformat # noqa: E402
import qpformat


def test_load_phase():
Expand All @@ -21,6 +18,11 @@ def test_load_phase():
assert ds.path == tf
assert "SingleNpyNumpy" in ds.__repr__()

try:
os.remove(tf)
except OSError:
pass


def test_load_field():
# generate test data
Expand All @@ -36,6 +38,11 @@ def test_load_field():
assert np.allclose(ds.get_qpimage().pha, phase, atol=1e-15, rtol=0)
assert np.allclose(ds.get_qpimage().amp, amplitude, atol=1e-15, rtol=0)

try:
os.remove(tf)
except OSError:
pass


if __name__ == "__main__":
# Run all tests
Expand Down
1 change: 1 addition & 0 deletions tests/test_storage_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_good_folder():
shutil.copy(str(path / "single_qpimage.h5"), str(dpath / "2.h5"))
ds = qpformat.load_data(dpath)
assert ds.storage_type == "phase,amplitude"
shutil.rmtree(str(dpath), ignore_errors=True)


if __name__ == "__main__":
Expand Down

0 comments on commit 1e8f4f5

Please sign in to comment.