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

Template for unit tests #187

Merged
merged 26 commits into from
Jun 5, 2023
Merged

Template for unit tests #187

merged 26 commits into from
Jun 5, 2023

Conversation

RondeauG
Copy link
Contributor

@RondeauG RondeauG commented Apr 13, 2023

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • Not really (at least not enough to resolve the issue)
  • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • This PR does not seem to break the templates.
  • HISTORY.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

  • Implements a working template on which to start creating unit tests for xscen.
  • Added NotImplementedError in climatological_mean and compute_deltas when using daily data.

Does this PR introduce a breaking change?

  • No.

Other information:

This is a start for #9

@RondeauG
Copy link
Contributor Author

@aulemahal @Zeitsperre Feel free to work directly on this branch and to change/remove what I've done. Once we're happy with the formatting, we'll merge it and I'll start making real unit tests.

tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
@RondeauG
Copy link
Contributor Author

What I'm uploading here is a version that uses test_timeseries and hits pretty much all of climatological_mean. Since this is the best time to establish a format, I'm open to all suggestions!

@RondeauG
Copy link
Contributor Author

Deux questionnements spécifiques:

  • Est-ce que test_all_default/test_options est correct ? Est-ce que je devrais les combiner en une seule grosse fonction qui teste à la fois les défauts et options ? Est-ce que je devrais au contraire séparer chaque option dans son propre test ?
  • Je dois redéclarer les mêmes timeseries plusieurs fois. Serait-ce mieux de les déclarer au tout début, en variable globale (ou à l'intérieur de TestClimatologicalMean) ?

tests/test_aggregate.py Outdated Show resolved Hide resolved
@aulemahal
Copy link
Collaborator

 @RondeauG
Please see the changes introduced in my latest commit.

  • Instead of looping inside the test function, I used pytest.mark.parametrize. The benefit here is that if a single element fails:
    • The others are also run
    • The pytest error output specifies the exact element causing the bug
    • And we can run a single element by hand if needed, while debugging.
  • I switched to conventionnal assert when we are comparing scalars.
  • I rewrote a check with a set logic instead of an all of a in comprehension list.
  • Rewrote the calendar check to use only xarray properties and pytest parametrize

@RondeauG RondeauG marked this pull request as ready for review May 31, 2023 21:01
@RondeauG
Copy link
Contributor Author

This should be good for review.

Copy link
Contributor

@Zeitsperre Zeitsperre left a comment

Choose a reason for hiding this comment

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

Will wait on @aulemahal's approval as well

Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

One comment to the changes in climatological_mean.

For the test, I think this is a good example of what we want. Even, it is on the exhaustive side, which is good.

Warning : all tests here are done on artificial data, and thus it may fail to tests some real-life caveats. When adding more tests, we could make use of xclim's test data too.


if to_level is not None:
ds_rolling.attrs["cat:processing_level"] = to_level
ds_rolling.attrs["cat:processing_level"] = to_level
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't fit the docstring, which says None is possible!
I'm guessing you want to change the docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, true! I got confused because the default is a string, not None. I'll reverse that.

@RondeauG RondeauG merged commit 866fabe into main Jun 5, 2023
@RondeauG RondeauG deleted the unittests branch June 5, 2023 14:50
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.

3 participants