]> granicus.if.org Git - python/commitdiff
output_difference(): In fancy-diff cases, the way this split expected &
authorTim Peters <tim.peters@gmail.com>
Thu, 26 Aug 2004 05:44:27 +0000 (05:44 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 26 Aug 2004 05:44:27 +0000 (05:44 +0000)
actual output into lines created spurious empty lines at the ends of
each.  Those matched, but the fancy diffs had surprising line counts (1
larger than expected), and tests kept having to slam <BLANKLINE> into the
expected output to account for this.  Using the splitlines() string method
with keepends=True instead accomplishes what was intended directly.

Lib/doctest.py
Lib/test/test_doctest.py

index 67de4c5a99f44ece6ebda9dec190e3af82b9c436..d8bc85211a8e0a30d2db8f5dfe19efc67f5a52a0 100644 (file)
@@ -1629,8 +1629,8 @@ class OutputChecker:
         # Check if we should use diff.
         if self._do_a_fancy_diff(want, got, optionflags):
             # Split want & got into lines.
-            want_lines = [l+'\n' for l in want.split('\n')]
-            got_lines = [l+'\n' for l in got.split('\n')]
+            want_lines = want.splitlines(True)  # True == keep line ends
+            got_lines = got.splitlines(True)
             # Use difflib to find their differences.
             if optionflags & REPORT_UDIFF:
                 diff = difflib.unified_diff(want_lines, got_lines, n=2)
index 2464b238d3a6ff76a86696f26fff425e18a08a0e..0f94fdf2a5b23bdd7d49ca47357a8f0e5953577d 100644 (file)
@@ -972,7 +972,7 @@ and actual outputs to be displayed using a unified diff:
     Failed example:
         print '\n'.join('abcdefg')
     Differences (unified diff with -expected +actual):
-        @@ -1,8 +1,8 @@
+        @@ -1,7 +1,7 @@
          a
         -B
         +b
@@ -982,7 +982,6 @@ and actual outputs to be displayed using a unified diff:
          f
          g
         -h
-    <BLANKLINE>
     (1, 1)
 
 The REPORT_CDIFF flag causes failures that involve multi-line expected
@@ -998,7 +997,7 @@ and actual outputs to be displayed using a context diff:
         print '\n'.join('abcdefg')
     Differences (context diff with expected followed by actual):
         ***************
-        *** 1,8 ****
+        *** 1,7 ****
           a
         ! B
           c
@@ -1006,8 +1005,7 @@ and actual outputs to be displayed using a context diff:
           f
           g
         - h
-    <BLANKLINE>
-        --- 1,8 ----
+        --- 1,7 ----
           a
         ! b
           c
@@ -1015,7 +1013,6 @@ and actual outputs to be displayed using a context diff:
         + e
           f
           g
-    <BLANKLINE>
     (1, 1)
 
 
@@ -1040,7 +1037,6 @@ marking, as well as interline differences.
         ?                       ^
         + a b  c d e f g h i   j k l m
         ?     +              ++    ^
-    <BLANKLINE>
     (1, 1)
 
 The REPORT_ONLY_FIRST_FAILURE supresses result output after the first