-
Notifications
You must be signed in to change notification settings - Fork 19
Update numerical file comparisons in tests #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,20 @@ def isfloat(s): | |
| return False | ||
|
|
||
|
|
||
| def compare_numeric(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): | ||
|
|
@@ -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") | ||
|
|
@@ -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) | ||
|
||
|
|
||
| def test_morphsqueeze_outputs(self, setup, tmp_path): | ||
| # The file squeeze_morph has a squeeze and stretch applied | ||
|
|
@@ -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): | ||
|
|
@@ -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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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