Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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>
42 changes: 18 additions & 24 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 compare_numeric(file1, file2):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably have a name like are_same(file1, file2) since it returns True if they are the same and False if they are not. Something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to are_files_same

"""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 @@ -108,7 +122,7 @@ def test_morph_outputs(self, setup, tmp_path):
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))
compare_numeric(generated, target)

# Save multiple verbose morphs
tmp_verbose = tmp_path.joinpath("verbose")
Expand Down Expand Up @@ -149,7 +163,7 @@ def test_morph_outputs(self, setup, tmp_path):
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))
compare_numeric(generated, target)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we call the options expected and actual to make the test more intelligible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved


def test_morphsqueeze_outputs(self, setup, tmp_path):
# The file squeeze_morph has a squeeze and stretch applied
Expand Down Expand Up @@ -184,17 +198,7 @@ def test_morphsqueeze_outputs(self, setup, tmp_path):
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]
compare_numeric(morphed, target)

def test_morphfuncy_outputs(self, tmp_path):
def quadratic(x, y, a0, a1, a2):
Expand All @@ -217,14 +221,4 @@ def quadratic(x, y, a0, a1, a2):
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]
compare_numeric(generated, target)
Loading