-
Notifications
You must be signed in to change notification settings - Fork 16
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
Adding test_plotting in tests #107
Conversation
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 need 3 extra steps to activate the image comparison tests here:
- add
pytest-mpl
to therequirements-dev.txt
file.. - generate the comparison images with
pytest --mpl-generate-path=tests/baseline
. - add the
--mpl
option in the line that run the tests in.github/workflows/tests.yml
.
You can find more about pytest-mpl
here.
tests/test_plotting.py
Outdated
from gliderpy.plotting import plot_transect | ||
from gliderpy.fetchers import GliderDataFetcher | ||
|
||
@pytest.mark.mpl_image_compare |
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 need to give the test function a directory where to look for the images for the comparison.
@pytest.mark.mpl_image_compare | |
@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/")) |
|
||
from gliderpy.plotting import plot_transect | ||
from gliderpy.fetchers import GliderDataFetcher | ||
|
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.
When using figures in tests we do not want matplotlib to fire up its Graphical User Interface (GUI) to avoid holding up the tests with a Window waiting to be closed.
import matplotlib as mpl | |
mpl.use("Agg") |
|
||
from gliderpy.plotting import plot_transect | ||
from gliderpy.fetchers import GliderDataFetcher | ||
|
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 use this to get the current directory to build the path to the baseline directory, where the images for the comparisons are held.
from pathlib import Path | |
root = Path(__file__).parent |
@FloraSauerbronn, as you can see the PR is failing as expected when we change the plot and the image deviates from the baseline. We can revert it back to |
Sorry @ocefpaf, I forgot to change it back before the push |
The tests are failing now b/c there is enough difference to trigger a real mismatch. The diff image is: That is probably b/c of fonts differences between you installation of matplotlib and the one in the CIs. BTW, what version of matplotlib do you have? I'll regenerate the image here and push to confirm if that is the case. |
As I suspected, the matplolib on my machine was able to create an image that had a match with the one in the CIs. We could also get this to pass by adjust the tolerance but, in this case, we could solve it without resorting to that. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
I'm using What is the CIs ? |
Continuous Integration. The system we are using to run the tests here. |
I'll merge this to reduce the merge conflicts and we can address the last pre-commit-ci failure in a new PR. |
Creating test_plotting.py with the first test of plot_transect, using pytest-mpl.