@@ -369,35 +369,13 @@ or run tests which contain names that match a specific keyword expression:
369
369
Writing an image-based test is only slightly more difficult than a simple test.
370
370
The main consideration is that you must specify the "baseline" or reference
371
371
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.
398
374
399
375
#### Using mpl_image_compare
400
376
377
+ > ** This is the preferred way to test plots whenever possible.**
378
+
401
379
This method uses the [ pytest-mpl] ( https://github.com/matplotlib/pytest-mpl )
402
380
plug-in to test plot generating code.
403
381
Every time the tests are run, ` pytest-mpl ` compares the generated plots with known
@@ -502,6 +480,24 @@ summarized as follows:
502
480
git push
503
481
dvc push
504
482
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
+
505
501
### Documentation
506
502
507
503
#### Building the documentation
0 commit comments