mirror of https://github.com/python/cpython
bpo-43651: Fix test_compileall with PEP 597 (GH-25128)
This commit is contained in:
parent
c0ec4486dc
commit
80017752ba
|
@ -407,7 +407,8 @@ def main():
|
||||||
# if flist is provided then load it
|
# if flist is provided then load it
|
||||||
if args.flist:
|
if args.flist:
|
||||||
try:
|
try:
|
||||||
with (sys.stdin if args.flist=='-' else open(args.flist)) as f:
|
with (sys.stdin if args.flist=='-' else
|
||||||
|
open(args.flist, encoding="utf-8")) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
compile_dests.append(line.strip())
|
compile_dests.append(line.strip())
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
|
@ -419,7 +419,7 @@ def _close_stdin():
|
||||||
try:
|
try:
|
||||||
fd = os.open(os.devnull, os.O_RDONLY)
|
fd = os.open(os.devnull, os.O_RDONLY)
|
||||||
try:
|
try:
|
||||||
sys.stdin = open(fd, closefd=False)
|
sys.stdin = open(fd, encoding="utf-8", closefd=False)
|
||||||
except:
|
except:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -58,7 +58,7 @@ class CompileallTestsBase:
|
||||||
self.directory = tempfile.mkdtemp()
|
self.directory = tempfile.mkdtemp()
|
||||||
self.source_path = os.path.join(self.directory, '_test.py')
|
self.source_path = os.path.join(self.directory, '_test.py')
|
||||||
self.bc_path = importlib.util.cache_from_source(self.source_path)
|
self.bc_path = importlib.util.cache_from_source(self.source_path)
|
||||||
with open(self.source_path, 'w') as file:
|
with open(self.source_path, 'w', encoding="utf-8") as file:
|
||||||
file.write('x = 123\n')
|
file.write('x = 123\n')
|
||||||
self.source_path2 = os.path.join(self.directory, '_test2.py')
|
self.source_path2 = os.path.join(self.directory, '_test2.py')
|
||||||
self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
|
self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
|
||||||
|
@ -73,7 +73,7 @@ class CompileallTestsBase:
|
||||||
|
|
||||||
def add_bad_source_file(self):
|
def add_bad_source_file(self):
|
||||||
self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
|
self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
|
||||||
with open(self.bad_source_path, 'w') as file:
|
with open(self.bad_source_path, 'w', encoding="utf-8") as file:
|
||||||
file.write('x (\n')
|
file.write('x (\n')
|
||||||
|
|
||||||
def timestamp_metadata(self):
|
def timestamp_metadata(self):
|
||||||
|
@ -164,7 +164,7 @@ class CompileallTestsBase:
|
||||||
data_file = os.path.join(data_dir, 'file')
|
data_file = os.path.join(data_dir, 'file')
|
||||||
os.mkdir(data_dir)
|
os.mkdir(data_dir)
|
||||||
# touch data/file
|
# touch data/file
|
||||||
with open(data_file, 'w'):
|
with open(data_file, 'wb'):
|
||||||
pass
|
pass
|
||||||
compileall.compile_file(data_file)
|
compileall.compile_file(data_file)
|
||||||
self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
|
self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
|
||||||
|
@ -440,8 +440,7 @@ class CommandLineTestsBase:
|
||||||
if not directory.is_dir():
|
if not directory.is_dir():
|
||||||
directory.mkdir()
|
directory.mkdir()
|
||||||
directory_created = True
|
directory_created = True
|
||||||
with path.open('w') as file:
|
path.write_text('# for test_compileall', encoding="utf-8")
|
||||||
file.write('# for test_compileall')
|
|
||||||
except OSError:
|
except OSError:
|
||||||
sys_path_writable = False
|
sys_path_writable = False
|
||||||
break
|
break
|
||||||
|
@ -704,7 +703,7 @@ class CommandLineTestsBase:
|
||||||
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
|
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
|
||||||
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
|
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
|
||||||
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
|
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
|
||||||
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
|
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
|
||||||
l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
|
l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
|
||||||
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
|
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
|
||||||
self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
|
self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
|
||||||
|
@ -718,7 +717,7 @@ class CommandLineTestsBase:
|
||||||
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
|
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
|
||||||
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
|
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
|
||||||
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
|
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
|
||||||
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
|
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
|
||||||
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
|
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
|
||||||
self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
|
self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
|
||||||
self.assertNotCompiled(f1)
|
self.assertNotCompiled(f1)
|
||||||
|
|
Loading…
Reference in New Issue