Skip to content

Commit 882aba4

Browse files
authored
Revert "[2.7] bpo-24746: Avoid stripping trailing whitespace in doctest fancy diff (#11482)"
This reverts commit 02e33d9.
1 parent e3db668 commit 882aba4

File tree

3 files changed

+4
-50
lines changed

3 files changed

+4
-50
lines changed

Lib/doctest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,8 @@ def output_difference(self, example, got, optionflags):
16511651
kind = 'ndiff with -expected +actual'
16521652
else:
16531653
assert 0, 'Bad diff option'
1654+
# Remove trailing whitespace on diff output.
1655+
diff = [line.rstrip() + '\n' for line in diff]
16541656
return 'Differences (%s):\n' % kind + _indent(''.join(diff))
16551657

16561658
# If we're not using diff, then simply list the expected

Lib/test/test_doctest.py

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,12 +2355,7 @@ def test_unittest_reportflags():
23552355
Then the default eporting options are ignored:
23562356
23572357
>>> result = suite.run(unittest.TestResult())
2358-
"""
2359-
"""
2360-
*NOTE*: These doctest are intentionally not placed in raw string to depict
2361-
the trailing whitespace using `\x20` in the diff below.
2362-
2363-
>>> print(result.failures[0][1]) # doctest: +ELLIPSIS
2358+
>>> print result.failures[0][1] # doctest: +ELLIPSIS
23642359
Traceback ...
23652360
Failed example:
23662361
favorite_color
@@ -2373,7 +2368,7 @@ def test_unittest_reportflags():
23732368
Differences (ndiff with -expected +actual):
23742369
a
23752370
- <BLANKLINE>
2376-
+\x20
2371+
+
23772372
b
23782373
<BLANKLINE>
23792374
<BLANKLINE>
@@ -2722,47 +2717,6 @@ def old_test4(): """
27222717
TestResults(failed=0, attempted=4)
27232718
"""
27242719

2725-
def test_no_trailing_whitespace_stripping():
2726-
r"""
2727-
The fancy reports had a bug for a long time where any trailing whitespace on
2728-
the reported diff lines was stripped, making it impossible to see the
2729-
differences in line reported as different that differed only in the amount of
2730-
trailing whitespace. The whitespace still isn't particularly visible unless
2731-
you use NDIFF, but at least it is now there to be found.
2732-
2733-
*NOTE*: This snippet was intentionally put inside a raw string to get rid of
2734-
leading whitespace error in executing the example below
2735-
2736-
>>> def f(x):
2737-
... r'''
2738-
... >>> print('\n'.join(['a ', 'b']))
2739-
... a
2740-
... b
2741-
... '''
2742-
"""
2743-
"""
2744-
*NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
2745-
using `\x20`
2746-
2747-
>>> test = doctest.DocTestFinder().find(f)[0]
2748-
>>> flags = doctest.REPORT_NDIFF
2749-
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
2750-
... # doctest: +ELLIPSIS
2751-
**********************************************************************
2752-
File ..., line 3, in f
2753-
Failed example:
2754-
print('\n'.join(['a ', 'b']))
2755-
Differences (ndiff with -expected +actual):
2756-
- a
2757-
+ a
2758-
b
2759-
TestResults(failed=1, attempted=1)
2760-
2761-
*NOTE*: `\x20` is for checking the trailing whitespace on the +a line above.
2762-
We cannot use actual spaces there, as a commit hook prevents from committing
2763-
patches that contain trailing whitespace. More info on Issue 24746.
2764-
"""
2765-
27662720
######################################################################
27672721
## Main
27682722
######################################################################

Misc/NEWS.d/next/Library/2018-11-22-15-22-56.bpo-24746.eSLKBE.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)