Skip to content

Test simplifications. #9497

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

Merged
merged 1 commit into from
Oct 28, 2017
Merged

Test simplifications. #9497

merged 1 commit into from
Oct 28, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 20, 2017

  • assert_produces_warning is now unused and has been replaced in the
    test suite by pytest.warns.

  • Replace assert x, y by assert x when the information in y is
    clearly redundant with what pytest's assert rewrite would produce.
    (There are a few cases where the message actually provides more
    information, these are left as is.)

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

"add_axes":
lambda fig: fig.add_axes([.1, .1, .8, .8]),
}[request.param]
return fig, make_ax(fig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this code prettier and actually it only partly checks what the functions return.

Copy link
Contributor Author

@anntzer anntzer Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to not have to add code to handle a case that should never happen (request.param being an invalid value -- it is controlled by the fixture params) while keeping clear the fact that an error (a KeyError) will be thrown if an invalid value ever comes in (... through some severely messed up bug in pytest).
If others also disagree (happy to hear more opinions), I'll revert.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the use of lambdas stored in a dict is improving readability here. Removing the else on the if is fine with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the offending part.

@tacaswell tacaswell added this to the v2.2 milestone Oct 21, 2017
# try getting the axes given an == (not is) polar projection
ax_via_gca = plt.gca(projection=prj3)
assert ax_via_gca is ax
plt.close()

# testing axes creation with subplot
ax = plt.subplot(121, projection=prj)
assert type(ax) == maxes._subplots._subplot_classes[PolarAxes], \
'Expected a PolarAxesSubplot, got %s' % type(ax)
assert type(ax) == maxes._subplots._subplot_classes[PolarAxes]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be isinstance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the point is to have an exact type check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my memory on isinstance was fuzzy at that moment.

@dopplershift
Copy link
Contributor

💯 on the idea behind this patch, just some minor things to work out.

- `assert_produces_warning` is now unused and has been replaced in the
  test suite by `pytest.warns`.

- Replace `assert x, y` by `assert x` when the information in `y` is
  clearly redundant with what pytest's assert rewrite would produce.
  (There are a few cases where the message actually provides more
  information, these are left as is.)
@anntzer
Copy link
Contributor Author

anntzer commented Oct 23, 2017

All issues addressed, I think.

@Kojoley Kojoley merged commit 0aaf239 into matplotlib:master Oct 28, 2017
@anntzer anntzer deleted the pytest-fixes branch October 28, 2017 14:37
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants