Skip to content

Commit

Permalink
Fix the example codes in the contributors guides (#2929)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Dec 29, 2023
1 parent 21a8722 commit 75e56e5
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```

0 comments on commit 75e56e5

Please sign in to comment.