-
Notifications
You must be signed in to change notification settings - Fork 101
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
Improve Test Coverage and Refactor Test for mslib.utils.coordinate #2596
base: develop
Are you sure you want to change the base?
Conversation
Add comprehensive test suite for `mslib.utils.coordinate` module - Refactored and added new test cases for functions in `coordinate` module. - Used `pytest.mark.parametrize` for parameterized testing. - Improved edge case coverage for distance, projection, and angle calculations. - Enhanced test readability and maintainability with detailed docstrings. - Validated linear and great circle path generation for lat/lon points.
tests/_test_utils/test_coordinate.py
Outdated
|
||
@pytest.mark.parametrize("ref_lats, ref_lons, numpoints", [ | ||
([0, 10], [0, 0], 2), | ||
([0, 10], [0, 0], 3), |
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.
the second one had before ([0, 0], [0, 10] ,3)
tests/_test_utils/test_coordinate.py
Outdated
assert all(np.asarray(lons) == [0, 5, 10]) | ||
numpoints=numpoints, connection="greatcircle") | ||
assert len(lats) == numpoints | ||
assert len(lons) == numpoints |
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.
We should also check for the expected value, like in assert all(np.asarray(lons) == [0, 5, 10])
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.
Hi @saiabhinav001
that makes it much better readable, thanks!
while the module we test here has no class definition we use a class level organization as namespace grouping. When test_linear maybe get named test_latlon_points_linear and the other test_latlon_points_greatcircle we maybe can remove all the grouping class names, what do you think?
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.
Hi @ReimarBauer
That's a great suggestion! Renaming the test functions makes them more descriptive, and removing the class-level grouping could simplify the structure.
I’ve updated the code by renaming test_linear
to test_latlon_points_linear
and test_greatcircle
to test_latlon_points_greatcircle
. I also removed the class-level groupings for simplicity and better readability. Let me know if there’s anything else to adjust!
Hi @saiabhinav001 Maybe a push to the repo is missing? I do see the class names here and also there is a lint failure. |
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.
Hi @ReimarBauer, I ensured there were no lint failures and pushed the repo.
@saiabhinav001 why do you have closed it? |
interesting how pytest.approx does this.
|
for numpoints, connection in [(100, "linear"), (100, "greatcircle")]: | ||
result = coordinate.path_points(lats, lons, numpoints, times=times, connection=connection) | ||
assert all(len(_x) == numpoints for _x in result) | ||
for i in range(3): |
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.
From the description of eric:
https://pytest-with-eric.com/pytest-advanced/pytest-approx/#Example-Code-To-Test-Pytest-Approx
I would expect:
assert result[i][0] == pytest.approx(ref[i][0])
assert result[i][-1] == pytest.approx(ref[i][-1])
tests/_test_utils/test_coordinate.py
Outdated
""" | ||
Test rotating points around the origin. | ||
""" | ||
assert coordinate.rotate_point(point, angle) == pytest.approx(rotated_point) |
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.
looks like you maybe found a bug by the ([0.0, 2.5], 45, (-1.7678, 1.7678)) example or the example has a problem.
How did you got to the -1.7678, 1.7678?
The test needs more digits, "pytest.approx considers the small variations due to floating-point imprecision." |
@saiabhinav001 Hi, have you seen my suggestions? Please have a look. |
Hi @ReimarBauer, Thank you for your valuable feedback and suggestions. The updated code for the
Please let me know if you have any further suggestions or questions. |
Hi @ReimarBauer, Thank you for pointing this out! I calculated the expected rotated point
For the point
This matches the expected result. However, I agree that using Please let me know if you'd like any further changes! Thanks again for your feedback. |
tests/_test_utils/test_coordinate.py
Outdated
import logging | ||
import datetime | ||
|
||
import numpy as np | ||
import pytest | ||
import pytest # type: ignore | ||
|
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 type: ignore is new here. What is it doing, just my interests in it. What is the reason for this?
the linter will likly want two blanks to seperate the comment
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 think that is not good to add it here. When we have type related issues, we won't see that now, correnct?
when we have type related problems indicated by pytest we have to review again.
whitespace findings from the linter
the codespell news are addressed in #2599 |
on github we need more digital places comparison failed. Mismatched elements: 2 / 2: Max absolute difference: 3.3047033631383727e-05 Max relative difference: 1.8694225263081064e-05 Index | Obtained | Expected 0 | -1.7677669529663687 | -1.7678 ± 1.8e-06 1 | 1.7677669529663689 | 1.7678 ± 1.8e-06
@@ -80,10 +80,12 @@ def test_normalize_angle(self): | |||
assert coordinate.fix_angle(420) == 60 | |||
|
|||
def test_rotate_point(self): | |||
assert coordinate.rotate_point([0, 0], 0) == (0.0, 0.0) |
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 do not see why the old tests should be removed. They provide coverage for corner cases and have no issues with decimal points. The new test is a good addition, though.
@saiabhinav001 please have a look on the request by @joernu76 |
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.
Hi @joernu76,
Thank you for highlighting the importance of retaining the old test cases. I have restored the original test cases alongside the new ones to ensure comprehensive coverage of corner cases. The combination of old and new tests provides a robust validation of the functionality while addressing potential edge cases.
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.
Hi @ReimarBauer,
The # type: ignore
comment was unnecessary and has been removed. I also resolved other linting issues, such as duplicate imports and missing blank lines, to ensure compliance with formatting
Hi @ReimarBauer, Thank you for pointing this out. I’ve reviewed @joernu76's feedback and addressed their concern regarding retaining the old tests. I have retained the original test cases alongside the new ones to ensure comprehensive test coverage. This ensures that both general scenarios and edge cases are thoroughly validated. |
This PR enhances the test suite for the
mslib.utils.coordinate
module.Key Updates:
Purpose of PR?:
Fixes #
Does this PR introduce a breaking change?
This PR does not introduce any breaking changes.
If the changes in this PR are manually verified, list down the scenarios covered::
If manually verified, the following scenarios were tested:
Additional information for reviewer? :
This PR is an independent contribution and does not depend on or continue from previous PRs.
Does this PR results in some Documentation changes?
No documentation changes are required.
Checklist:
<type>: <subject>