[Python-checkins] cpython (3.4): Issue #20599: Force ASCII encoding for stdout in test_cleanup() of test_builtin

larry.hastings python-checkins at python.org
Mon Mar 17 07:33:02 CET 2014


http://hg.python.org/cpython/rev/c978dffb95ac
changeset:   89772:c978dffb95ac
branch:      3.4
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Feb 12 18:27:55 2014 +0100
summary:
  Issue #20599: Force ASCII encoding for stdout in test_cleanup() of test_builtin

On Windows, the codec of sys.stdout is implemented in Python. At exit, the
codec may be unloaded before the destructor tries to write something to
sys.stdout.

files:
  Lib/test/test_builtin.py |  14 +++++++++++---
  1 files changed, 11 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -1604,10 +1604,10 @@
 
             class C:
                 def __del__(self):
-                    print("before", flush=True)
+                    print("before")
                     # Check that builtins still exist
                     len(())
-                    print("after", flush=True)
+                    print("after")
 
             c = C()
             # Make this module survive until builtins and sys are cleaned
@@ -1617,7 +1617,15 @@
             # through a GC phase.
             here = sys.modules[__name__]
             """
-        rc, out, err = assert_python_ok("-c", code)
+        # Issue #20599: Force ASCII encoding to get a codec implemented in C,
+        # otherwise the codec may be unloaded before C.__del__() is called, and
+        # so print("before") fails because the codec cannot be used to encode
+        # "before" to sys.stdout.encoding. For example, on Windows,
+        # sys.stdout.encoding is the OEM code page and these code pages are
+        # implemented in Python
+        rc, out, err = assert_python_ok("-c", code,
+                                        PYTHONIOENCODING="ascii",
+                                        __cleanenv=True)
         self.assertEqual(["before", "after"], out.decode().splitlines())
 
 

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


More information about the Python-checkins mailing list