Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b08b4d

Browse files
author
Victor Stinner
committed
Oops, add the new test_log.py for distutils test suite (missing part of r81359)
1 parent 1802d3f commit 5b08b4d

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lib/distutils/tests/test_log.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Tests for distutils.log"""
2+
3+
import sys
4+
import unittest
5+
from tempfile import NamedTemporaryFile
6+
7+
from distutils import log
8+
9+
class TestLog(unittest.TestCase):
10+
def test_non_ascii(self):
11+
# Issue #8663: test that non-ASCII text is escaped with
12+
# backslashreplace error handler (stream use ASCII encoding and strict
13+
# error handler)
14+
old_stdout = sys.stdout
15+
old_stderr = sys.stderr
16+
try:
17+
log.set_threshold(log.DEBUG)
18+
with NamedTemporaryFile(mode="w+", encoding='ascii') as stdout, \
19+
NamedTemporaryFile(mode="w+", encoding='ascii') as stderr:
20+
sys.stdout = stdout
21+
sys.stderr = stderr
22+
log.debug("debug:\xe9")
23+
log.fatal("fatal:\xe9")
24+
stdout.seek(0)
25+
self.assertEquals(stdout.read().rstrip(), "debug:\\xe9")
26+
stderr.seek(0)
27+
self.assertEquals(stderr.read().rstrip(), "fatal:\\xe9")
28+
finally:
29+
sys.stdout = old_stdout
30+
sys.stderr = old_stderr
31+
32+
def test_suite():
33+
return unittest.makeSuite(TestLog)
34+
35+
if __name__ == "__main__":
36+
unittest.main(defaultTest="test_suite")

0 commit comments

Comments
 (0)