Skip to content

[3.7] Revert "bpo-24746: Avoid stripping trailing whitespace in doctest fan… #11498

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,8 @@ def output_difference(self, example, got, optionflags):
kind = 'ndiff with -expected +actual'
else:
assert 0, 'Bad diff option'
# Remove trailing whitespace on diff output.
diff = [line.rstrip() + '\n' for line in diff]
return 'Differences (%s):\n' % kind + _indent(''.join(diff))

# If we're not using diff, then simply list the expected
Expand Down
48 changes: 1 addition & 47 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,11 +2450,6 @@ def test_unittest_reportflags():
Then the default eporting options are ignored:

>>> result = suite.run(unittest.TestResult())
"""
"""
*NOTE*: These doctest are intentionally not placed in raw string to depict
the trailing whitespace using `\x20` in the diff below.

>>> print(result.failures[0][1]) # doctest: +ELLIPSIS
Traceback ...
Failed example:
Expand All @@ -2468,7 +2463,7 @@ def test_unittest_reportflags():
Differences (ndiff with -expected +actual):
a
- <BLANKLINE>
+\x20
+
b
<BLANKLINE>
<BLANKLINE>
Expand Down Expand Up @@ -2957,47 +2952,6 @@ def test_CLI(): r"""

"""

def test_no_trailing_whitespace_stripping():
r"""
The fancy reports had a bug for a long time where any trailing whitespace on
the reported diff lines was stripped, making it impossible to see the
differences in line reported as different that differed only in the amount of
trailing whitespace. The whitespace still isn't particularly visible unless
you use NDIFF, but at least it is now there to be found.

*NOTE*: This snippet was intentionally put inside a raw string to get rid of
leading whitespace error in executing the example below

>>> def f(x):
... r'''
... >>> print('\n'.join(['a ', 'b']))
... a
... b
... '''
"""
"""
*NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
using `\x20`

>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.REPORT_NDIFF
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
... # doctest: +ELLIPSIS
**********************************************************************
File ..., line 3, in f
Failed example:
print('\n'.join(['a ', 'b']))
Differences (ndiff with -expected +actual):
- a
+ a
b
TestResults(failed=1, attempted=1)

*NOTE*: `\x20` is for checking the trailing whitespace on the +a line above.
We cannot use actual spaces there, as a commit hook prevents from committing
patches that contain trailing whitespace. More info on Issue 24746.
"""

######################################################################
## Main
######################################################################
Expand Down

This file was deleted.