Skip to content
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

Test interp nominal lon #365

Merged
merged 14 commits into from
Jul 9, 2024

Conversation

JoranAngevaare
Copy link
Contributor

Fix test for _interp_nominal_lon

This PR is some leftover work from #296 (and #300)

PR checks

Copy link
Owner

@jbusecke jbusecke left a comment

Choose a reason for hiding this comment

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

Thanks for putting in more work into polishing this up @JoranAngevaare! I would much prefer to keep this in pure pytest, but I might also be missing something here.

tests/test_preprocessing.py Outdated Show resolved Hide resolved
def test_new_works(self):
lons = self._get_dummy_longitude()
lons_parsed = _interp_nominal_lon(lons)
if not self._lons_parsed_make_sense(lons, lons_parsed):
Copy link
Owner

Choose a reason for hiding this comment

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

I am not quite sure this will actually test correctly with pytest. I have only ever written funtions with assert statements. See https://docs.pytest.org/en/stable/getting-started.html

If you want to ensure that a certain Exceptio is raised you can wrap the statement with

with pytest.raises(...)
    ...

lons_parsed = self._interp_nominal_lon_old(lons)
if self._lons_parsed_make_sense(lons, lons_parsed):
raise ValueError(
"Parsed lons should be gibberish, but somehow the old implementation also works?"
Copy link
Owner

Choose a reason for hiding this comment

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

See my other comment. That will hopefully lead this to actually fail? Once that is the case I wouöd suggest to remove the "old way" logic to keep this test more compact

@JoranAngevaare
Copy link
Contributor Author

@jbusecke of course value-errors result in failed tests and this syntax does trigger the tests:

(py39) aangevaare@surfclimahuge:~/software/xMIP$ pytest tests/test_preprocessing.py -k TestReplaceXYNominalLatLon
================================================= test session starts ==================================================
platform linux -- Python 3.9.0, pytest-8.2.2, pluggy-1.5.0 -- /home/aangevaare/miniconda3/envs/py39/bin/python
cachedir: .pytest_cache
rootdir: /home/aangevaare/software/xMIP
configfile: pyproject.toml
collected 140 items / 138 deselected / 2 selected

tests/test_preprocessing.py::TestReplaceXYNominalLatLon::test_old_fails PASSED                                   [ 50%]
tests/test_preprocessing.py::TestReplaceXYNominalLatLon::test_new_works PASSED                                   [100%]

=================================================== warnings summary ===================================================
xmip/preprocessing.py:4
  /home/aangevaare/software/xMIP/xmip/preprocessing.py:4: UserWarning: Import(s) unavailable to set up matplotlib support...skipping this portion of the setup.
    import cf_xarray.units  # noqa: F401

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
===================================== 2 passed, 138 deselected, 1 warning in 8.37s =====================================

But sure, let me write assert statements if that's more conform the way things are done for xmip

@JoranAngevaare
Copy link
Contributor Author

@jbusecke as requested:

  • I replaced the raise ValueError with assert 9faf75f.
  • To show that it works explicitly, I pushed 0270f4b which reverts the logic, and shows that the old code would have raised an error.
  • I think you asked me to remove the showcase of the old test. In that case, using a class is of course completely redundant so I wrote it as a single function in fda6fbc.

Copy link
Owner

@jbusecke jbusecke left a comment

Choose a reason for hiding this comment

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

Thank you so much for iterating on this @JoranAngevaare . Really appreciate the ongoing work. I had a minor ? about s comment, but otherwise I think this is ready!

lons_parsed = _interp_nominal_lon(lons)
assert _lons_parsed_make_sense(
lons, lons_parsed
), "Parsed lons after the fix of #296 are still bad?"
Copy link
Owner

Choose a reason for hiding this comment

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

The tests are now passing, so this comment confuses me slightly. Is it a leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the message that the AssertionError will produce once failed, see for example the message in https://github.com/jbusecke/xMIP/actions/runs/9857864431/job/27217936984 (pytest also prints the lons, and lons_parsed so it looks a bit messy).

Of course, it shouldn't (and doesn't) fail so I could as well remove it

Copy link
Owner

Choose a reason for hiding this comment

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

That would be awesome! Ill merge it right away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! I already pushed the commit

@jbusecke
Copy link
Owner

jbusecke commented Jul 9, 2024

of course value-errors result in failed tests and this syntax does trigger the tests

Thanks for verifying this. And it obviously makes sense (Ill keep that in mind for future test designs, and thanks for teachibg me this!). I should have tested this myself (but am using gh on mobile so am a bit restricted here).

@jbusecke jbusecke merged commit 108266e into jbusecke:main Jul 9, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding new contributors to CITATION.cff replace_x_y_nominal_lat_lon does not work for > 360 lon coordinates
2 participants