[Python-checkins] Revert "bpo-24746: Avoid stripping trailing whitespace in doctest fancy diff (GH-10639) (GH-11477)" (GH-11509)

Ned Deily webhook-mailer at python.org
Thu Jan 10 13:56:14 EST 2019


https://github.com/python/cpython/commit/d09e8cecf214b1de457feae01860f5592f912a8e
commit: d09e8cecf214b1de457feae01860f5592f912a8e
branch: 3.6
author: Senthil Kumaran <skumaran at gatech.edu>
committer: Ned Deily <nad at python.org>
date: 2019-01-10T13:56:02-05:00
summary:

Revert "bpo-24746: Avoid stripping trailing whitespace in doctest fancy diff (GH-10639) (GH-11477)" (GH-11509)

This reverts commit 5d9ae8b9df8371dd65514e0d60b561fd37056986 which was merged to 3.6 in error.

files:
D Misc/NEWS.d/next/Library/2018-11-22-15-22-56.bpo-24746.eSLKBE.rst
M Lib/doctest.py
M Lib/test/test_doctest.py

diff --git a/Lib/doctest.py b/Lib/doctest.py
index ca5be5927594..0b78544d8d0e 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -1691,6 +1691,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
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index ad527626d1b0..2258c6b1baed 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -2431,11 +2431,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:
@@ -2449,7 +2444,7 @@ def test_unittest_reportflags():
       Differences (ndiff with -expected +actual):
             a
           - <BLANKLINE>
-          +\x20
+          +
             b
       <BLANKLINE>
       <BLANKLINE>
@@ -2938,47 +2933,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
 ######################################################################
diff --git a/Misc/NEWS.d/next/Library/2018-11-22-15-22-56.bpo-24746.eSLKBE.rst b/Misc/NEWS.d/next/Library/2018-11-22-15-22-56.bpo-24746.eSLKBE.rst
deleted file mode 100644
index c592516d1466..000000000000
--- a/Misc/NEWS.d/next/Library/2018-11-22-15-22-56.bpo-24746.eSLKBE.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-Avoid stripping trailing whitespace in doctest fancy diff. Orignial patch by
-R. David Murray & Jairo Trad. Enhanced by Sanyam Khurana.



More information about the Python-checkins mailing list