diff options
author | Stefan Hoelzl <1478183+stefanhoelzl@users.noreply.github.com> | 2021-07-30 16:38:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 16:38:42 (GMT) |
commit | 80f07076294bc09a55ed76d9bbf307404eef25e6 (patch) | |
tree | 5a419fedf23bb306171060ae8ae19c97a0d80c72 /Lib/test/test_compileall.py | |
parent | 7cad0bee80a536c7e47f54cf43174175834f30a0 (diff) | |
download | cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.zip cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.tar.gz cpython-80f07076294bc09a55ed76d9bbf307404eef25e6.tar.bz2 |
bpo-44666: Use default encoding as fallback for compile_file (GH-27236)
When sys.stdout.encoding is None compile_file will fall back to
sys.getdefaultencoding to encode/decode error messages.
Co-authored-by: Stefan Hoelzl <stefan.hoelzl@posteo.de>
Co-authored-by: Mickaƫl Schoentgen <contact@tiger-222.fr>
Diffstat (limited to 'Lib/test/test_compileall.py')
-rw-r--r-- | Lib/test/test_compileall.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index 96a0f8f..4612953 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -169,6 +169,14 @@ class CompileallTestsBase: compileall.compile_file(data_file) self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__'))) + + def test_compile_file_encoding_fallback(self): + # Bug 44666 reported that compile_file failed when sys.stdout.encoding is None + self.add_bad_source_file() + with contextlib.redirect_stdout(io.StringIO()): + self.assertFalse(compileall.compile_file(self.bad_source_path)) + + def test_optimize(self): # make sure compiling with different optimization settings than the # interpreter's creates the correct file names |