Skip to content

Commit c064d4a

Browse files
willschlitzerweiji14Meghan Jones
authored
Update the check_figures_equal testing section in CONTRIBUTING.md (#1108)
Co-authored-by: Wei Ji <[email protected]> Co-authored-by: Meghan Jones <[email protected]>
1 parent 28d37ec commit c064d4a

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

CONTRIBUTING.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -369,35 +369,13 @@ or run tests which contain names that match a specific keyword expression:
369369
Writing an image-based test is only slightly more difficult than a simple test.
370370
The main consideration is that you must specify the "baseline" or reference
371371
image, and compare it with a "generated" or test image. This is handled using
372-
the *decorator* functions `@check_figures_equal` and
373-
`@pytest.mark.mpl_image_compare` whose usage are further described below.
374-
375-
#### Using check_figures_equal
376-
377-
This approach draws the same figure using two different methods (the reference
378-
method and the tested method), and checks that both of them are the same.
379-
It takes two `pygmt.Figure` objects ('fig_ref' and 'fig_test'), generates a png
380-
image, and checks for the Root Mean Square (RMS) error between the two.
381-
Here's an example:
382-
383-
```python
384-
@check_figures_equal()
385-
def test_my_plotting_case():
386-
"Test that my plotting function works"
387-
fig_ref, fig_test = Figure(), Figure()
388-
fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
389-
fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
390-
return fig_ref, fig_test
391-
```
392-
393-
Note: This is the recommended way to test plots whenever possible, such as when
394-
we want to compare a reference GMT plot created from NetCDF files with one
395-
generated by PyGMT that passes through several layers of virtualfile machinery.
396-
Using this method will help save space in the git repository by not having to
397-
store baseline images as with the other method below.
372+
the *decorator* functions `@pytest.mark.mpl_image_compare` and `@check_figures_equal`
373+
whose usage are further described below.
398374

399375
#### Using mpl_image_compare
400376

377+
> **This is the preferred way to test plots whenever possible.**
378+
401379
This method uses the [pytest-mpl](https://github.com/matplotlib/pytest-mpl)
402380
plug-in to test plot generating code.
403381
Every time the tests are run, `pytest-mpl` compares the generated plots with known
@@ -502,6 +480,24 @@ summarized as follows:
502480
git push
503481
dvc push
504482

483+
#### Using check_figures_equal
484+
485+
This approach draws the same figure using two different methods (the reference
486+
method and the tested method), and checks that both of them are the same.
487+
It takes two `pygmt.Figure` objects ('fig_ref' and 'fig_test'), generates a png
488+
image, and checks for the Root Mean Square (RMS) error between the two.
489+
Here's an example:
490+
491+
```python
492+
@check_figures_equal()
493+
def test_my_plotting_case():
494+
"Test that my plotting function works"
495+
fig_ref, fig_test = Figure(), Figure()
496+
fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
497+
fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
498+
return fig_ref, fig_test
499+
```
500+
505501
### Documentation
506502

507503
#### Building the documentation

0 commit comments

Comments
 (0)