Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/update_tests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
58 changes: 26 additions & 32 deletions tests/test_morphio.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def isfloat(s):
return False


def are_files_same(file1, file2):
"""Assert that two files have (approximately) the same numerical
values."""
for f1_row, f2_row in zip(file1, file2):
f1_arr = f1_row.split()
f2_arr = f2_row.split()
assert len(f1_arr) == len(f2_arr)
for idx, _ in enumerate(f1_arr):
if isfloat(f1_arr[idx]) and isfloat(f2_arr[idx]):
assert np.isclose(float(f1_arr[idx]), float(f2_arr[idx]))
else:
assert f1_arr[idx] == f2_arr[idx]


class TestApp:
@pytest.fixture
def setup(self):
Expand Down Expand Up @@ -106,9 +120,9 @@ def test_morph_outputs(self, setup, tmp_path):
for file in common:
with open(tmp_succinct.joinpath(file)) as gf:
with open(test_saving_succinct.joinpath(file)) as tf:
generated = filter(ignore_path, gf)
target = filter(ignore_path, tf)
assert all(x == y for x, y in zip(generated, target))
actual = filter(ignore_path, gf)
expected = filter(ignore_path, tf)
are_files_same(actual, expected)

# Save multiple verbose morphs
tmp_verbose = tmp_path.joinpath("verbose")
Expand Down Expand Up @@ -147,9 +161,9 @@ def test_morph_outputs(self, setup, tmp_path):
for file in common:
with open(tmp_verbose.joinpath(file)) as gf:
with open(test_saving_verbose.joinpath(file)) as tf:
generated = filter(ignore_path, gf)
target = filter(ignore_path, tf)
assert all(x == y for x, y in zip(generated, target))
actual = filter(ignore_path, gf)
expected = filter(ignore_path, tf)
are_files_same(actual, expected)

def test_morphsqueeze_outputs(self, setup, tmp_path):
# The file squeeze_morph has a squeeze and stretch applied
Expand Down Expand Up @@ -182,19 +196,9 @@ def test_morphsqueeze_outputs(self, setup, tmp_path):
# Check squeeze morph generates the correct output
with open(sqr) as mf:
with open(target_file) as tf:
morphed = filter(ignore_path, mf)
target = filter(ignore_path, tf)
for m, t in zip(morphed, target):
m_row = m.split()
t_row = t.split()
assert len(m_row) == len(t_row)
for idx, _ in enumerate(m_row):
if isfloat(m_row[idx]) and isfloat(t_row[idx]):
assert np.isclose(
float(m_row[idx]), float(t_row[idx])
)
else:
assert m_row[idx] == t_row[idx]
actual = filter(ignore_path, mf)
expected = filter(ignore_path, tf)
are_files_same(actual, expected)

def test_morphfuncy_outputs(self, tmp_path):
def quadratic(x, y, a0, a1, a2):
Expand All @@ -215,16 +219,6 @@ def quadratic(x, y, a0, a1, a2):

with open(testdata_dir.joinpath("funcy_target.cgr")) as tf:
with open(tmp_path.joinpath("funcy_target.cgr")) as gf:
generated = filter(ignore_path, gf)
target = filter(ignore_path, tf)
for m, t in zip(generated, target):
m_row = m.split()
t_row = t.split()
assert len(m_row) == len(t_row)
for idx, _ in enumerate(m_row):
if isfloat(m_row[idx]) and isfloat(t_row[idx]):
assert np.isclose(
float(m_row[idx]), float(t_row[idx])
)
else:
assert m_row[idx] == t_row[idx]
actual = filter(ignore_path, gf)
expected = filter(ignore_path, tf)
are_files_same(actual, expected)
18 changes: 16 additions & 2 deletions tests/test_morphpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ class Chain:
assert np.allclose(
[rw], [self.morphapp_results[target_file.name]["Rw"]]
)
assert morph_results == self.morphapp_results
# Check values in dictionaries are approximately equal
for file in morph_results.keys():
morph_params = morph_results[file]
morphapp_params = self.morphapp_results[file]
for key in morph_params.keys():
assert morph_params[key] == pytest.approx(
morphapp_params[key], abs=1e-08
)

def test_morphpy(self, setup_morph):
morph_results = {}
Expand All @@ -113,7 +120,14 @@ class Chain:
assert np.allclose(
[rw], [self.morphapp_results[target_file.name]["Rw"]]
)
assert morph_results == self.morphapp_results
# Check values in dictionaries are approximately equal
for file in morph_results.keys():
morph_params = morph_results[file]
morphapp_params = self.morphapp_results[file]
for key in morph_params.keys():
assert morph_params[key] == pytest.approx(
morphapp_params[key], abs=1e-08
)

def test_morphfuncy(self, setup_morph):
def gaussian(x, mu, sigma):
Expand Down
Loading