[Python-checkins] cpython: #11390: fix test failures due to readline and windows lineneds.

r.david.murray python-checkins at python.org
Tue Jun 25 14:11:46 CEST 2013


http://hg.python.org/cpython/rev/8f22e03f5f07
changeset:   84339:8f22e03f5f07
user:        R David Murray <rdmurray at bitdance.com>
date:        Tue Jun 25 08:11:22 2013 -0400
summary:
  #11390: fix test failures due to readline and windows lineneds.

files:
  Lib/test/test_doctest.py |  54 ++++++++++++++++-----------
  1 files changed, 31 insertions(+), 23 deletions(-)


diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -2601,10 +2601,22 @@
 These tests test this CLI functionality.
 
 We'll use the support module's script_helpers for this, and write a test files
-to a temp dir to run the command against.
-
-First, a file with two simple tests and no errors.  We'll run both the
-unadorned doctest command, and the verbose version, and then check the output:
+to a temp dir to run the command against.  Due to a current limitation in
+script_helpers, though, we need a little utility function to turn the returned
+output into something we can doctest against:
+
+    >>> def normalize(s):
+    ...     return '\n'.join(s.decode().splitlines())
+
+Note: we also pass TERM='' to all the assert_python calls to avoid a bug
+in the readline library that is triggered in these tests because we are
+running them in a new python process.  See:
+
+  http://lists.gnu.org/archive/html/bug-readline/2013-06/msg00000.html
+
+With those preliminaries out of the way, we'll start with a file with two
+simple tests and no errors.  We'll run both the unadorned doctest command, and
+the verbose version, and then check the output:
 
     >>> from test import script_helper
     >>> with script_helper.temp_dir() as tmpdir:
@@ -2618,9 +2630,9 @@
     ...         _ = f.write('\n')
     ...         _ = f.write('And that is it.\n')
     ...     rc1, out1, err1 = script_helper.assert_python_ok(
-    ...             '-m', 'doctest', fn)
+    ...             '-m', 'doctest', fn, TERM='')
     ...     rc2, out2, err2 = script_helper.assert_python_ok(
-    ...             '-m', 'doctest', '-v', fn)
+    ...             '-m', 'doctest', '-v', fn, TERM='')
 
 With no arguments and passing tests, we should get no output:
 
@@ -2631,7 +2643,7 @@
 
     >>> rc2, err2
     (0, b'')
-    >>> print(out2.decode())
+    >>> print(normalize(out2))
     Trying:
         1 + 1
     Expecting:
@@ -2647,7 +2659,6 @@
     2 tests in 1 items.
     2 passed and 0 failed.
     Test passed.
-    <BLANKLINE>
 
 Now we'll write a couple files, one with three tests, the other a python module
 with two tests, both of the files having "errors" in the tests that can be made
@@ -2684,17 +2695,17 @@
     ...         _ = f.write('   \"\"\"\n')
     ...     import shutil
     ...     rc1, out1, err1 = script_helper.assert_python_failure(
-    ...             '-m', 'doctest', fn, fn2)
+    ...             '-m', 'doctest', fn, fn2, TERM='')
     ...     rc2, out2, err2 = script_helper.assert_python_ok(
-    ...             '-m', 'doctest', '-o', 'ELLIPSIS', fn)
+    ...             '-m', 'doctest', '-o', 'ELLIPSIS', fn, TERM='')
     ...     rc3, out3, err3 = script_helper.assert_python_ok(
     ...             '-m', 'doctest', '-o', 'ELLIPSIS',
-    ...             '-o', 'NORMALIZE_WHITESPACE', fn, fn2)
+    ...             '-o', 'NORMALIZE_WHITESPACE', fn, fn2, TERM='')
     ...     rc4, out4, err4 = script_helper.assert_python_failure(
-    ...             '-m', 'doctest', '-f', fn, fn2)
+    ...             '-m', 'doctest', '-f', fn, fn2, TERM='')
     ...     rc5, out5, err5 = script_helper.assert_python_ok(
     ...             '-m', 'doctest', '-v', '-o', 'ELLIPSIS',
-    ...             '-o', 'NORMALIZE_WHITESPACE', fn, fn2)
+    ...             '-o', 'NORMALIZE_WHITESPACE', fn, fn2, TERM='')
 
 Our first test run will show the errors from the first file (doctest stops if a
 file has errors).  Note that doctest test-run error output appears on stdout,
@@ -2702,7 +2713,7 @@
 
     >>> rc1, err1
     (1, b'')
-    >>> print(out1.decode())                # doctest: +ELLIPSIS
+    >>> print(normalize(out1))                # doctest: +ELLIPSIS
     **********************************************************************
     File "...myfile.doc", line 4, in myfile.doc
     Failed example:
@@ -2723,7 +2734,6 @@
     1 items had failures:
        2 of   3 in myfile.doc
     ***Test Failed*** 2 failures.
-    <BLANKLINE>
 
 With -o ELLIPSIS specified, the second run, against just the first file, should
 produce no errors, and with -o NORMALIZE_WHITESPACE also specified, neither
@@ -2738,7 +2748,7 @@
 
     >>> rc4, err4
     (1, b'')
-    >>> print(out4.decode())                # doctest: +ELLIPSIS
+    >>> print(normalize(out4))                # doctest: +ELLIPSIS
     **********************************************************************
     File "...myfile.doc", line 4, in myfile.doc
     Failed example:
@@ -2751,14 +2761,13 @@
     1 items had failures:
        1 of   2 in myfile.doc
     ***Test Failed*** 1 failures.
-    <BLANKLINE>
 
 The fifth test uses verbose with the two options, so we should get verbose
 success output for the tests in both files:
 
     >>> rc5, err5
     (0, b'')
-    >>> print(out5.decode())
+    >>> print(normalize(out5))
     Trying:
         1 + 1
     Expecting:
@@ -2796,17 +2805,16 @@
     2 tests in 2 items.
     2 passed and 0 failed.
     Test passed.
-    <BLANKLINE>
 
 We should also check some typical error cases.
 
 Invalid file name:
 
     >>> rc, out, err = script_helper.assert_python_failure(
-    ...         '-m', 'doctest', 'nosuchfile')
+    ...         '-m', 'doctest', 'nosuchfile', TERM='')
     >>> rc, out
     (1, b'')
-    >>> print(err.decode())                    # doctest: +ELLIPSIS
+    >>> print(normalize(err))                    # doctest: +ELLIPSIS
     Traceback (most recent call last):
       ...
     FileNotFoundError: [Errno ...] No such file or directory: 'nosuchfile'
@@ -2814,10 +2822,10 @@
 Invalid doctest option:
 
     >>> rc, out, err = script_helper.assert_python_failure(
-    ...         '-m', 'doctest', '-o', 'nosuchoption')
+    ...         '-m', 'doctest', '-o', 'nosuchoption', TERM='')
     >>> rc, out
     (2, b'')
-    >>> print(err.decode())                    # doctest: +ELLIPSIS
+    >>> print(normalize(err))                    # doctest: +ELLIPSIS
     usage...invalid...nosuchoption...
 
 """

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list