Skip to content

Add test for _num_to_string method used in __call__ of LogFormatter #8598

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 8 commits into from
May 10, 2017

Conversation

patniharshit
Copy link
Contributor

@patniharshit patniharshit commented May 9, 2017

PR Summary

Closes #8597

Write tests for LogFormatter to explicitly test the return value of __call__ .

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/whats_new.rst if major new feature
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

ax.xaxis.set_major_formatter(lf)

assert str(lf(val)) is not None

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I would follow the testing style used below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't realize that there was an option to create a fake axis without having a full plot set up.

# test _num_to_string method used in __call__
temp_lf = mticker.LogFormatter()
temp_lf.axis = FakeAxis()
assert str(temp_lf(10)) is not None
Copy link
Member

Choose a reason for hiding this comment

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

Can we do a bit better and check that 1, 10, 100, 1000 are correctly rendered (not None is the example I used in the issue but is a pretty blunt test :) )

# test _num_to_string method used in __call__
temp_lf = mticker.LogFormatter()
temp_lf.axis = FakeAxis()
assert str(temp_lf(val)) is not None
Copy link
Member

Choose a reason for hiding this comment

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

this is still testing that result is not None (and str(None) is not None). Can you check that these are equal to the expected value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry missed that in earlier commit. Now done.

call_data = [
1, 10, 100, 1000
]

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 think this should be here. If you want to make a full-on fixture that is used in many tests, use pytest to mark it as such. Otherwise, just define this within the test that uses it.

@@ -521,6 +525,13 @@ def test_sublabel(self):
ax.set_xlim(0.5, 0.9)
self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))

@pytest.mark.parametrize('val', call_data)
Copy link
Member

Choose a reason for hiding this comment

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

If you're not going to provide multiple values for val, I wouldn't bother parametrizing the test. Just define val/call_data inside the test.

Copy link
Member

Choose a reason for hiding this comment

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

The list does provide multiple values to val.

Copy link
Member

@phobson phobson left a comment

Choose a reason for hiding this comment

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

@patniharshit This is looks. Note that I was confused the last time I reviewed this and your parametrization was fine, but the values didn't need to be defined outside of the decorator.

Sorry for being so unclear and thanks for the PR!

@phobson phobson merged commit 7d6b0c8 into matplotlib:master May 10, 2017
@QuLogic QuLogic added this to the 2.1 (next point release) milestone May 11, 2017
@patniharshit patniharshit deleted the logformatter branch May 11, 2017 03:18
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.

Improve test for LogFormatter
5 participants