-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Conversation
lib/matplotlib/tests/test_ticker.py
Outdated
ax.xaxis.set_major_formatter(lf) | ||
|
||
assert str(lf(val)) is not None | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/matplotlib/tests/test_ticker.py
Outdated
# test _num_to_string method used in __call__ | ||
temp_lf = mticker.LogFormatter() | ||
temp_lf.axis = FakeAxis() | ||
assert str(temp_lf(10)) is not None |
There was a problem hiding this comment.
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 :) )
lib/matplotlib/tests/test_ticker.py
Outdated
# test _num_to_string method used in __call__ | ||
temp_lf = mticker.LogFormatter() | ||
temp_lf.axis = FakeAxis() | ||
assert str(temp_lf(val)) is not None |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
lib/matplotlib/tests/test_ticker.py
Outdated
call_data = [ | ||
1, 10, 100, 1000 | ||
] | ||
|
There was a problem hiding this comment.
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.
lib/matplotlib/tests/test_ticker.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this 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!
PR Summary
Closes #8597
Write tests for LogFormatter to explicitly test the return value of
__call__
.PR Checklist