Skip to content

Commit d09e8ce

Browse files
orsenthilned-deily
authored andcommitted
Revert "bpo-24746: Avoid stripping trailing whitespace in doctest fancy diff (GH-10639) (GH-11477)" (GH-11509)
This reverts commit 5d9ae8b which was merged to 3.6 in error.
1 parent 5d9ae8b commit d09e8ce

3 files changed

Lines changed: 3 additions & 49 deletions

File tree

Lib/doctest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,8 @@ def output_difference(self, example, got, optionflags):
16911691
kind = 'ndiff with -expected +actual'
16921692
else:
16931693
assert 0, 'Bad diff option'
1694+
# Remove trailing whitespace on diff output.
1695+
diff = [line.rstrip() + '\n' for line in diff]
16941696
return 'Differences (%s):\n' % kind + _indent(''.join(diff))
16951697

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

Lib/test/test_doctest.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,11 +2431,6 @@ def test_unittest_reportflags():
24312431
Then the default eporting options are ignored:
24322432
24332433
>>> result = suite.run(unittest.TestResult())
2434-
"""
2435-
"""
2436-
*NOTE*: These doctest are intentionally not placed in raw string to depict
2437-
the trailing whitespace using `\x20` in the diff below.
2438-
24392434
>>> print(result.failures[0][1]) # doctest: +ELLIPSIS
24402435
Traceback ...
24412436
Failed example:
@@ -2449,7 +2444,7 @@ def test_unittest_reportflags():
24492444
Differences (ndiff with -expected +actual):
24502445
a
24512446
- <BLANKLINE>
2452-
+\x20
2447+
+
24532448
b
24542449
<BLANKLINE>
24552450
<BLANKLINE>
@@ -2938,47 +2933,6 @@ def test_CLI(): r"""
29382933
29392934
"""
29402935

2941-
def test_no_trailing_whitespace_stripping():
2942-
r"""
2943-
The fancy reports had a bug for a long time where any trailing whitespace on
2944-
the reported diff lines was stripped, making it impossible to see the
2945-
differences in line reported as different that differed only in the amount of
2946-
trailing whitespace. The whitespace still isn't particularly visible unless
2947-
you use NDIFF, but at least it is now there to be found.
2948-
2949-
*NOTE*: This snippet was intentionally put inside a raw string to get rid of
2950-
leading whitespace error in executing the example below
2951-
2952-
>>> def f(x):
2953-
... r'''
2954-
... >>> print('\n'.join(['a ', 'b']))
2955-
... a
2956-
... b
2957-
... '''
2958-
"""
2959-
"""
2960-
*NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
2961-
using `\x20`
2962-
2963-
>>> test = doctest.DocTestFinder().find(f)[0]
2964-
>>> flags = doctest.REPORT_NDIFF
2965-
>>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
2966-
... # doctest: +ELLIPSIS
2967-
**********************************************************************
2968-
File ..., line 3, in f
2969-
Failed example:
2970-
print('\n'.join(['a ', 'b']))
2971-
Differences (ndiff with -expected +actual):
2972-
- a
2973-
+ a
2974-
b
2975-
TestResults(failed=1, attempted=1)
2976-
2977-
*NOTE*: `\x20` is for checking the trailing whitespace on the +a line above.
2978-
We cannot use actual spaces there, as a commit hook prevents from committing
2979-
patches that contain trailing whitespace. More info on Issue 24746.
2980-
"""
2981-
29822936
######################################################################
29832937
## Main
29842938
######################################################################

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)