[Python-checkins] r81361 - python/branches/py3k/Lib/distutils/tests/test_log.py

victor.stinner python-checkins at python.org
Wed May 19 19:15:50 CEST 2010


Author: victor.stinner
Date: Wed May 19 19:15:50 2010
New Revision: 81361

Log:
Oops, add the new test_log.py for distutils test suite (missing part of r81359)


Added:
   python/branches/py3k/Lib/distutils/tests/test_log.py

Added: python/branches/py3k/Lib/distutils/tests/test_log.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/distutils/tests/test_log.py	Wed May 19 19:15:50 2010
@@ -0,0 +1,36 @@
+"""Tests for distutils.log"""
+
+import sys
+import unittest
+from tempfile import NamedTemporaryFile
+
+from distutils import log
+
+class TestLog(unittest.TestCase):
+    def test_non_ascii(self):
+        # Issue #8663: test that non-ASCII text is escaped with
+        # backslashreplace error handler (stream use ASCII encoding and strict
+        # error handler)
+        old_stdout = sys.stdout
+        old_stderr = sys.stderr
+        try:
+            log.set_threshold(log.DEBUG)
+            with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
+                 NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
+                sys.stdout = stdout
+                sys.stderr = stderr
+                log.debug("debug:\xe9")
+                log.fatal("fatal:\xe9")
+                stdout.seek(0)
+                self.assertEquals(stdout.read().rstrip(), "debug:\\xe9")
+                stderr.seek(0)
+                self.assertEquals(stderr.read().rstrip(), "fatal:\\xe9")
+        finally:
+            sys.stdout = old_stdout
+            sys.stderr = old_stderr
+
+def test_suite():
+    return unittest.makeSuite(TestLog)
+
+if __name__ == "__main__":
+    unittest.main(defaultTest="test_suite")


More information about the Python-checkins mailing list