mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00

svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r81359 | victor.stinner | 2010-05-19 19:00:07 +0200 (mer., 19 mai 2010) | 4 lines Issue #8663: distutils.log emulates backslashreplace error handler. Fix compilation in a non-ASCII directory if stdout encoding is ASCII (eg. if stdout is not a TTY). ........ r81360 | victor.stinner | 2010-05-19 19:11:19 +0200 (mer., 19 mai 2010) | 5 lines regrtest.py: call replace_stdout() before the first call to print() print("== ", os.getcwd()) fails if the current working directory is not ASCII whereas sys.stdout encoding is ASCII. ........ r81361 | victor.stinner | 2010-05-19 19:15:50 +0200 (mer., 19 mai 2010) | 2 lines Oops, add the new test_log.py for distutils test suite (missing part of r81359) ........
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""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")
|