From 16ebdc93faa9adb56c24ddffd0ae9ce1c5bb8311 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 06:55:34 +0000 Subject: [PATCH 1/3] move check_figures_equal explanation, change which is the preferred method of testing --- CONTRIBUTING.md | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9668e76e023..bc1103a0588 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -372,32 +372,10 @@ image, and compare it with a "generated" or test image. This is handled using the *decorator* functions `@check_figures_equal` and `@pytest.mark.mpl_image_compare` whose usage are further described below. -#### Using check_figures_equal - -This approach draws the same figure using two different methods (the reference -method and the tested method), and checks that both of them are the same. -It takes two `pygmt.Figure` objects ('fig_ref' and 'fig_test'), generates a png -image, and checks for the Root Mean Square (RMS) error between the two. -Here's an example: - -```python -@check_figures_equal() -def test_my_plotting_case(): - "Test that my plotting function works" - fig_ref, fig_test = Figure(), Figure() - fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo") - fig_test.grdimage(grid, projection="W120/15c", cmap="geo") - return fig_ref, fig_test -``` - -Note: This is the recommended way to test plots whenever possible, such as when -we want to compare a reference GMT plot created from NetCDF files with one -generated by PyGMT that passes through several layers of virtualfile machinery. -Using this method will help save space in the git repository by not having to -store baseline images as with the other method below. - #### Using mpl_image_compare +**This is the preferred way to test plots whenever possible.** + This method uses the [pytest-mpl](https://github.com/matplotlib/pytest-mpl) plug-in to test plot generating code. Every time the tests are run, `pytest-mpl` compares the generated plots with known @@ -502,6 +480,24 @@ summarized as follows: git push dvc push +#### Using check_figures_equal + +This approach draws the same figure using two different methods (the reference +method and the tested method), and checks that both of them are the same. +It takes two `pygmt.Figure` objects ('fig_ref' and 'fig_test'), generates a png +image, and checks for the Root Mean Square (RMS) error between the two. +Here's an example: + +```python +@check_figures_equal() +def test_my_plotting_case(): + "Test that my plotting function works" + fig_ref, fig_test = Figure(), Figure() + fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo") + fig_test.grdimage(grid, projection="W120/15c", cmap="geo") + return fig_ref, fig_test +``` + ### Documentation #### Building the documentation From b9c31a03c43081dd942d240ae8aafd562d0886fd Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 09:28:02 +0000 Subject: [PATCH 2/3] Update CONTRIBUTING.md Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bc1103a0588..045122a2688 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -369,8 +369,8 @@ or run tests which contain names that match a specific keyword expression: Writing an image-based test is only slightly more difficult than a simple test. The main consideration is that you must specify the "baseline" or reference image, and compare it with a "generated" or test image. This is handled using -the *decorator* functions `@check_figures_equal` and -`@pytest.mark.mpl_image_compare` whose usage are further described below. +the *decorator* functions `@pytest.mark.mpl_image_compare` and `@check_figures_equal` +whose usage are further described below. #### Using mpl_image_compare From ec14aef1d31c4416755ba6d9f8290287e8c6cc8b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 23 Mar 2021 18:07:06 +0000 Subject: [PATCH 3/3] Update CONTRIBUTING.md Co-authored-by: Meghan Jones --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 045122a2688..23c75b934d1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -374,7 +374,7 @@ whose usage are further described below. #### Using mpl_image_compare -**This is the preferred way to test plots whenever possible.** +> **This is the preferred way to test plots whenever possible.** This method uses the [pytest-mpl](https://github.com/matplotlib/pytest-mpl) plug-in to test plot generating code.