summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compileall.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2010-03-16 13:19:21 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2010-03-16 13:19:21 (GMT)
commit4b00307425bb3219f269a13ba5a9526903d21ce8 (patch)
tree8731e9ad5b15c88f637daad50f3b5bcc51ca1a07 /Lib/test/test_compileall.py
parent09c86afb1e3b2f1af8a03f77f2dd146429f56add (diff)
downloadcpython-4b00307425bb3219f269a13ba5a9526903d21ce8.zip
cpython-4b00307425bb3219f269a13ba5a9526903d21ce8.tar.gz
cpython-4b00307425bb3219f269a13ba5a9526903d21ce8.tar.bz2
Issue #6716/2: Backslash-replace error output in compilall.
Diffstat (limited to 'Lib/test/test_compileall.py')
-rw-r--r--Lib/test/test_compileall.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index 65622f7..4b6feba 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -1,3 +1,4 @@
+import sys
import compileall
import imp
import os
@@ -7,6 +8,7 @@ import struct
import tempfile
from test import support
import unittest
+import io
class CompileallTests(unittest.TestCase):
@@ -72,8 +74,30 @@ class CompileallTests(unittest.TestCase):
os.unlink(self.bc_path)
os.unlink(self.bc_path2)
+class EncodingTest(unittest.TestCase):
+ 'Issue 6716: compileall should escape source code when printing errors to stdout.'
+
+ def setUp(self):
+ self.directory = tempfile.mkdtemp()
+ self.source_path = os.path.join(self.directory, '_test.py')
+ with open(self.source_path, 'w', encoding='utf-8') as file:
+ file.write('# -*- coding: utf-8 -*-\n')
+ file.write('print u"\u20ac"\n')
+
+ def tearDown(self):
+ shutil.rmtree(self.directory)
+
+ def test_error(self):
+ try:
+ orig_stdout = sys.stdout
+ sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
+ compileall.compile_dir(self.directory)
+ finally:
+ sys.stdout = orig_stdout
+
def test_main():
- support.run_unittest(CompileallTests)
+ support.run_unittest(CompileallTests,
+ EncodingTest)
if __name__ == "__main__":