-
Notifications
You must be signed in to change notification settings - Fork 21
Refactor division by zero error test in test_tth_to_d
#260
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
Changes from all commits
2a3d7c8
f8704f1
12e2b89
765c9e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * catch division by zero warning messages in tests | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,19 +117,32 @@ def test_tth_to_q_bad(wavelength, tth, expected_error_type, expected_error_msg): | |
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "q, expected_d", | ||
| "q, expected_d, warning_expected", | ||
| [ | ||
| # UC1: User specified empty q values | ||
| (np.array([]), np.array([])), | ||
| # UC2: User specified valid q values | ||
| # Test conversion of q to d with valid values | ||
| # Case 1: empty q values, expect empty d values | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's put a high level contextual statement always to make it easier to review. To see what I mean you could look at my edits to the PR on scale_to and eq. Here it would be something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| (np.array([]), np.array([]), False), | ||
| # Case 2: | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 1. valid q values, expect d values without warning | ||
| ( | ||
| np.array([0.1, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi]), | ||
| np.array([62.83185307, 2, 1, 0.66667, 0.5, 0.4]), | ||
| False, | ||
| ), | ||
| # 2. valid q values containing 0, expect d values with divide by zero warning | ||
| ( | ||
| np.array([0, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi]), | ||
| np.array([np.inf, 2, 1, 0.66667, 0.5, 0.4]), | ||
| True, | ||
| ), | ||
| ], | ||
| ) | ||
| def test_q_to_d(q, expected_d): | ||
| actual_d = q_to_d(q) | ||
| def test_q_to_d(q, expected_d, warning_expected): | ||
| if warning_expected: | ||
| with pytest.warns(RuntimeWarning, match="divide by zero encountered in divide"): | ||
| actual_d = q_to_d(q) | ||
| else: | ||
| actual_d = q_to_d(q) | ||
| assert np.allclose(actual_d, expected_d) | ||
|
|
||
|
|
||
|
|
||
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.
I am thinking having
warning_expectedexplicitly provides a quick overview whether each test case provides a warning or not. @sbillinge how do you like it?