-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Single-line string notation for subplot_mosaic #18763
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,6 +758,24 @@ def test_subplot_kw(self, fig_test, fig_ref, subplot_kw): | |
|
||
axB = fig_ref.add_subplot(gs[0, 1], **subplot_kw) | ||
|
||
def test_string_parser(self): | ||
normalize = Figure._normalize_grid_string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should possibly be paramterized instead of reassigning the function name if the point of the reassignment is to not have to write the long name (& also these tests are really testing different conditions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you strictly go by the book, yes all these assertions could be separate tests and thus be parametrized. However, from a practical point of view, an explicit
And for readability, I'll accept shortening the function name and doing all assertions in one test. IMHO that's still better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure test output readability is better though? (I don't know what the output looks like here. Also my concern isn't readability so much as there's no way to see that multiple conditions fail since by definition the first failed assert will fail the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the test passes there is no output. In case of failure, you get a traceback including a printout of the failed assert statement. IMHO the assert is a bit more readable with the explicit strings, compared to using variables and resolving them ("... where str_layout = ... and list_layout = ..."). But actually I'm more concerned with the readability of the test. The tests are validated examples. They define the API we actually guarantee (docstrings can claim anything). Thus, they are a source of information and should be easily readable. You are right with the multiple conditions. It's very well possible that multiple assertions fail if someone messes up the parser. However, I believe that knowing multiple asserts failed does not help for debugging in this context. Pytest will tell you the number of broken tests. If there is one, you go there and immediately see "My change broke the mosaic parser". If you have 3 failed tests, you have to check all three to see that you only broke the parser but nothing else. This is significantly more cumbersome. IMHO the added information "My change broke the mosaic parser in three ways" does not help much. In practice, you will anyway go to the first failed test and try to make that work again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @timhoffm this is is more readable an informative than what it would look like with |
||
assert normalize('ABC') == [['A', 'B', 'C']] | ||
assert normalize('AB;CC') == [['A', 'B'], ['C', 'C']] | ||
assert normalize('AB;CC;DE') == [['A', 'B'], ['C', 'C'], ['D', 'E']] | ||
assert normalize(""" | ||
ABC | ||
""") == [['A', 'B', 'C']] | ||
assert normalize(""" | ||
AB | ||
CC | ||
""") == [['A', 'B'], ['C', 'C']] | ||
assert normalize(""" | ||
AB | ||
CC | ||
DE | ||
""") == [['A', 'B'], ['C', 'C'], ['D', 'E']] | ||
|
||
@check_figures_equal(extensions=["png"]) | ||
@pytest.mark.parametrize("str_pattern", | ||
["AAA\nBBB", "\nAAA\nBBB\n", "ABC\nDEF"] | ||
|
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.
Why not do if ';' in layout? Should ';\nA' be valid?
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've designed this PR to not change the behavior of multi-line strings. I've just added the possibility of single-line strings. Therefore the check is between those two options ("Do I have a line break?").
Whether or not we want stronger checking for the multi-line case is orthogonal.