ยปCore Development>Code coverage>Lib/distutils/tests/test_log.py

Python code coverage for Lib/distutils/tests/test_log.py

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