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

Directly check if two figures returned by a function are equal #95

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

weiji14
Copy link

@weiji14 weiji14 commented Sep 4, 2020

Check two figures (generated using slightly different methods) returned by a test function directly, similar to matplotlib's check_figures_equal function. Open to suggestions on names and implementation details.

Option 1

Original idea which is to follow matplotlib's style (see https://matplotlib.org/3.3.1/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal):

@pytest.mark.mpl_check_equal
def test_check_equal(fig_test, fig_ref):
    fig_test.subplots().plot([1, 3, 5])
    fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])

Option 2

Probably easier to implement, and we can reuse the same @pytest.mark.mpl_image_compare decorator, but there might be compatibility issues from some users?

@pytest.mark.mpl_image_compare
def test_check_equal():
    fig_test = plt.figure()
    fig_test.subplots().plot([1, 3, 5])

    fig_ref = plt.figure()
    fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])

    return fig_test, fig_ref    

Option 3?

Some mix of the above two? Maybe another alternative solution?

Will resolve #94

@weiji14 weiji14 changed the title WIP Extend pytest-mpl to have a check_figures_equal marker WIP Extend pytest-mpl to check two figures directly Sep 4, 2020
@weiji14 weiji14 changed the title WIP Extend pytest-mpl to check two figures directly WIP Directly check if two figures returned by a function are equal Sep 4, 2020
Also added test to check that the skipping works, and test for unequal images too.
@weiji14 weiji14 changed the title WIP Directly check if two figures returned by a function are equal Directly check if two figures returned by a function are equal Sep 7, 2020
@dopplershift
Copy link
Contributor

I like option 1 above. I haven't reviewed the implementation in detail, but I like the concept in general.

@weiji14
Copy link
Author

weiji14 commented Sep 12, 2020

Hiya, I've actually ended up implementing Option 2 in this PR since it was easier (and more explicit), and also because I couldn't work out how to have two different marks (@pytest.mark.mpl_check_equal and @pytest.mark.mpl_image_compare) in the same pytest plugin. Option 2 is also less matplotlib specific (see GenericMappingTools/pygmt#590), but yes, I think we can discuss about how we want to go about with implementing this feature 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support check_figures_equal style comparison without any baseline_image
2 participants