-
Notifications
You must be signed in to change notification settings - Fork 122
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
Insert newlines if issue numbers would be inserted inside a code block #624
Changes from 3 commits
d05e420
b8454da
231f2ab
63c4c43
a8b3931
4a30295
c3792a0
fb995e1
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Multi-line newsfragments that ends with a code block will now have a newline inserted before appending the link to the issue, to avoid breaking formatting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,3 +462,100 @@ def test_line_wrapping_disabled(self): | |
versiondata={"name": "MyProject", "version": "1.0", "date": "never"}, | ||
) | ||
self.assertEqual(output, expected_output) | ||
|
||
def test_trailing_block(self): | ||
""" | ||
Make sure a newline gets inserted before appending the issue number, if the | ||
newsfragment ends with an indented block. | ||
""" | ||
|
||
fragments = { | ||
"": { | ||
( | ||
"1", | ||
"feature", | ||
0, | ||
): "text::\n\n def foo(): ..." | ||
} | ||
} | ||
expected_output = """MyProject 1.0 (never) | ||
===================== | ||
|
||
Features | ||
-------- | ||
|
||
- text:: | ||
|
||
def foo(): ... | ||
|
||
(#1) | ||
|
||
|
||
""" | ||
|
||
# TODO: I copy-pasted the below lines from previous test, they probably contain | ||
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. this needs to be cleanup before merge. 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 .. don't think it contains irrelevant crap currently? But I'm not overly familiar with your test structure so it's very possible it still does. |
||
# crap that's irrelevant to this test. | ||
definitions = { | ||
"feature": {"name": "Features", "showcontent": True}, | ||
} | ||
template = read_pkg_resource("templates/default.rst") | ||
|
||
fragments = split_fragments(fragments, definitions) | ||
output = render_fragments( | ||
template, | ||
None, | ||
fragments, | ||
definitions, | ||
["-", "~"], | ||
wrap=True, | ||
versiondata={"name": "MyProject", "version": "1.0", "date": "never"}, | ||
) | ||
self.assertEqual(output, expected_output) | ||
|
||
def test_trailing_block_nondefault_bullets(self): | ||
""" | ||
Test insertion of newlines after code block with single-file-no-bullets. | ||
""" | ||
# TODO: I expected this to break with the issue number being indented, but | ||
# instead I got an extra newline? Which seems fine? | ||
|
||
fragments = { | ||
"": { | ||
( | ||
"1", | ||
"feature", | ||
0, | ||
): "text::\n\n def foo(): ..." | ||
} | ||
} | ||
expected_output = """MyProject 1.0 (never) | ||
===================== | ||
|
||
Features | ||
-------- | ||
|
||
text:: | ||
|
||
def foo(): ... | ||
|
||
|
||
(#1) | ||
|
||
""" | ||
|
||
definitions = { | ||
"feature": {"name": "Features", "showcontent": True}, | ||
} | ||
template = read_pkg_resource("templates/single-file-no-bullets.rst") | ||
|
||
fragments = split_fragments(fragments, definitions) | ||
output = render_fragments( | ||
template, | ||
None, | ||
fragments, | ||
definitions, | ||
["-", "~"], | ||
wrap=True, | ||
versiondata={"name": "MyProject", "version": "1.0", "date": "never"}, | ||
) | ||
self.assertEqual(output, expected_output) |
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 think is best to have this comment as a docstring and explain why use case for this function.
and maybe move it outside of
render_fragments
.The TODOs needs to be fixed before merge.
If they can't be fixed, we should have followup GitHub Issues created for each TODO and the comments should contain a link to the GitHub Issue
I know that we have
get_indent
that is embedded and has a comment instead of docstring... but I think (subjective opinion) that is a bad code practiceThere 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.
Moved it outside of
render_fragments
, added docstring, and added a bunch of comments explaining the regex logic. Which is also very much changed because I realized it was horribly broken >.>Personally I don't think embedded functions are a bad practice if the function is only intended as a helper for that one specific function and is exceedingly unlikely to be used by any other function, but having it outside is plenty fine. Mentioned it only being used by
render_fragments
in its docstring.