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