2010-05-19 14:15:50 -03:00
|
|
|
"""Tests for distutils.log"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
from tempfile import NamedTemporaryFile
|
2010-11-05 23:44:43 -03:00
|
|
|
from test.support import run_unittest
|
2010-05-19 14:15:50 -03:00
|
|
|
|
|
|
|
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
|
2015-11-12 07:15:41 -04:00
|
|
|
old_threshold = log.set_threshold(log.DEBUG)
|
2010-05-19 14:15:50 -03:00
|
|
|
try:
|
|
|
|
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)
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(stdout.read().rstrip(), "debug:\\xe9")
|
2010-05-19 14:15:50 -03:00
|
|
|
stderr.seek(0)
|
2010-11-20 15:04:17 -04:00
|
|
|
self.assertEqual(stderr.read().rstrip(), "fatal:\\xe9")
|
2010-05-19 14:15:50 -03:00
|
|
|
finally:
|
2015-11-12 07:15:41 -04:00
|
|
|
log.set_threshold(old_threshold)
|
2010-05-19 14:15:50 -03:00
|
|
|
sys.stdout = old_stdout
|
|
|
|
sys.stderr = old_stderr
|
|
|
|
|
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(TestLog)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-11-05 23:44:43 -03:00
|
|
|
run_unittest(test_suite())
|