From 75e56e5ac23ad3a58fe0105b4ee24301f158615a Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 29 Dec 2023 20:23:48 +0800 Subject: [PATCH] Fix the example codes in the contributors guides (#2929) --- doc/contributing.md | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/doc/contributing.md b/doc/contributing.md index ef5cbb31df8..5f560cca83e 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -320,24 +320,24 @@ Open `doc/_build/html/index.html` in your browser to view the pages. Follow the Many of the PyGMT functions have example code in their documentation. To contribute an example, add an "Example" header and put the example code below it. Have all lines begin with `>>>`. To keep this example code from being run during testing, add the code -`__doctest_skip__ = [function name]` to the top of the module. +`__doctest_skip__ = ["function_name"]` to the top of the module. **Inline code example** Below the import statements at the top of the file -`` -__doctest_skip__ = ["module_name"] -`` - -At the end of the function's docstring +```python +__doctest_skip__ = ["function_name"] - Example - ------- - >>> import pygmt - >>> # Comment describing what is happening - >>> Code example +At the end of the function's docstring: +```python +Example +------- +>>> import pygmt +>>> # Comment describing what is happening +>>> Code example +``` ### Contributing Gallery Plots @@ -580,7 +580,9 @@ returning the `pygmt.Figure` object: ```python @pytest.mark.mpl_image_compare def test_my_plotting_case(): - "Test that my plotting method works" + """ + Test that my plotting method works. + """ fig = Figure() fig.basemap(region=[0, 360, -90, 90], projection="W15c", frame=True) return fig @@ -675,20 +677,22 @@ summarized as follows: dvc push # Run before git push to enable automated testing with the new images git push -#### Using check_figures_equal +#### 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 +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 method 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 + """ + Test that my plotting method 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 ```