Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign check_figures_equal testing function to be more explicit #590

Merged
merged 2 commits into from
Sep 7, 2020

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Sep 7, 2020

Description of proposed changes

Improve readability of test code by explicitly declaring fig_ref and fig_test as pygmt.Figure objects, and returning the two figures to be compared against. Makes each testing code more standalone, though it will become 3 lines longer.

Before

@check_figures_equal()
def test_my_plotting_case(fig_ref, fig_test):
  "Test that my plotting function works"
  fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
  fig_test.grdimage(grid, projection="W120/15c", cmap="geo")

After

@check_figures_equal()
def test_my_plotting_case():
  "Test that my plotting function works"
  fig_ref = pygmt.Figure()
  fig_ref.grdimage("@earth_relief_01d_g", projection="W120/15c", cmap="geo")
  fig_test = pygmt.Figure()
  fig_test.grdimage(grid, projection="W120/15c", cmap="geo")
  return fig_ref, fig_test

This PR is a small redesign of #555, and works towards #579 (vendoring the @check_figure_equal decorator to pytest-mpl.

Fixes #

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Improve readability of test code by explicitly declaring fig_ref and fig_test as pygmt.Figure objects, and returning the two figures to be compared against. Makes each testing code more standalone, though it will become 3 lines longer.
@weiji14 weiji14 added the maintenance Boring but important stuff for the core devs label Sep 7, 2020
@weiji14 weiji14 marked this pull request as ready for review September 7, 2020 03:50
@weiji14 weiji14 merged commit 5a17858 into master Sep 7, 2020
@weiji14 weiji14 deleted the redesign_check_figures_equal branch September 7, 2020 05:55
weiji14 added a commit that referenced this pull request Sep 9, 2020
Removes the expected failures (xfail) pytest marks
used as a workaround in #503 to deal with grdview failures.

* Refactor test to use new check_figures_equal syntax from #590
* Refactor grdview test to use grdcut instead of load_earth_relief

The xarray based slicing isn't as precise as grdcut,
so some images were a few pixels off when plotted in 3D.

* Rename grid explicitly to xrgrid, and use kwargs to reduce code length
* Set a Transverse Mercator projection for zaxis_frame test

Otherwise GMT (fig_ref) might plot double-lined x and y axis frame,
while PyGMT (fig_test) plots a single-lined frame.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants