bpo-45783: Preserve file moves and deletions in the tests for the freeze tool. (GH-29527)
Use shutil.copytree rather than Git, which might be missing (or configured differently) when testing Python built from a source release.
This commit is contained in:
parent
b48ac6fe38
commit
8ed1495ad9
@ -5,6 +5,7 @@ import textwrap
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
|
|
||||||
from . import imports_under_tool, skip_if_missing
|
from . import imports_under_tool, skip_if_missing
|
||||||
skip_if_missing('freeze')
|
skip_if_missing('freeze')
|
||||||
@ -22,8 +23,8 @@ class TestFreeze(unittest.TestCase):
|
|||||||
print('running...')
|
print('running...')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
""")
|
""")
|
||||||
outdir, scriptfile, python = helper.prepare(script)
|
with os_helper.temp_dir() as outdir:
|
||||||
|
outdir, scriptfile, python = helper.prepare(script, outdir)
|
||||||
executable = helper.freeze(python, scriptfile, outdir)
|
executable = helper.freeze(python, scriptfile, outdir)
|
||||||
text = helper.run(executable)
|
text = helper.run(executable)
|
||||||
self.assertEqual(text, 'running...')
|
self.assertEqual(text, 'running...')
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
The test for the freeze tool now handles file moves and deletions.
|
@ -11,7 +11,6 @@ TOOL_ROOT = os.path.dirname(TESTS_DIR)
|
|||||||
SRCDIR = os.path.dirname(os.path.dirname(TOOL_ROOT))
|
SRCDIR = os.path.dirname(os.path.dirname(TOOL_ROOT))
|
||||||
|
|
||||||
MAKE = shutil.which('make')
|
MAKE = shutil.which('make')
|
||||||
GIT = shutil.which('git')
|
|
||||||
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')
|
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')
|
||||||
OUTDIR = os.path.join(TESTS_DIR, 'outdir')
|
OUTDIR = os.path.join(TESTS_DIR, 'outdir')
|
||||||
|
|
||||||
@ -75,36 +74,15 @@ def ensure_opt(args, name, value):
|
|||||||
args[pos] = f'{opt}={value}'
|
args[pos] = f'{opt}={value}'
|
||||||
|
|
||||||
|
|
||||||
def git_copy_repo(newroot, oldroot):
|
def copy_source_tree(newroot, oldroot):
|
||||||
if not GIT:
|
print(f'copying the source tree into {newroot}...')
|
||||||
raise UnsupportedError('git')
|
|
||||||
|
|
||||||
if os.path.exists(newroot):
|
if os.path.exists(newroot):
|
||||||
print(f'updating copied repo {newroot}...')
|
|
||||||
if newroot == SRCDIR:
|
if newroot == SRCDIR:
|
||||||
raise Exception('this probably isn\'t what you wanted')
|
raise Exception('this probably isn\'t what you wanted')
|
||||||
_run_quiet([GIT, 'clean', '-d', '-f'], newroot)
|
shutil.rmtree(newroot)
|
||||||
_run_quiet([GIT, 'reset'], newroot)
|
shutil.copytree(oldroot, newroot)
|
||||||
_run_quiet([GIT, 'checkout', '.'], newroot)
|
if os.path.exists(os.path.join(newroot, 'Makefile')):
|
||||||
_run_quiet([GIT, 'pull', '-f', oldroot], newroot)
|
_run_quiet([MAKE, 'clean'], newroot)
|
||||||
else:
|
|
||||||
print(f'copying repo into {newroot}...')
|
|
||||||
_run_quiet([GIT, 'clone', oldroot, newroot])
|
|
||||||
|
|
||||||
# Copy over any uncommited files.
|
|
||||||
text = _run_stdout([GIT, 'status', '-s'], oldroot)
|
|
||||||
for line in text.splitlines():
|
|
||||||
_, _, relfile = line.strip().partition(' ')
|
|
||||||
relfile = relfile.strip()
|
|
||||||
isdir = relfile.endswith(os.path.sep)
|
|
||||||
relfile = relfile.rstrip(os.path.sep)
|
|
||||||
srcfile = os.path.join(oldroot, relfile)
|
|
||||||
dstfile = os.path.join(newroot, relfile)
|
|
||||||
os.makedirs(os.path.dirname(dstfile), exist_ok=True)
|
|
||||||
if isdir:
|
|
||||||
shutil.copytree(srcfile, dstfile, dirs_exist_ok=True)
|
|
||||||
else:
|
|
||||||
shutil.copy2(srcfile, dstfile)
|
|
||||||
|
|
||||||
|
|
||||||
def get_makefile_var(builddir, name):
|
def get_makefile_var(builddir, name):
|
||||||
@ -146,12 +124,14 @@ def prepare(script=None, outdir=None):
|
|||||||
# Write the script to disk.
|
# Write the script to disk.
|
||||||
if script:
|
if script:
|
||||||
scriptfile = os.path.join(outdir, 'app.py')
|
scriptfile = os.path.join(outdir, 'app.py')
|
||||||
|
print(f'creating the script to be frozen at {scriptfile}')
|
||||||
with open(scriptfile, 'w') as outfile:
|
with open(scriptfile, 'w') as outfile:
|
||||||
outfile.write(script)
|
outfile.write(script)
|
||||||
|
|
||||||
# Make a copy of the repo to avoid affecting the current build.
|
# Make a copy of the repo to avoid affecting the current build
|
||||||
|
# (e.g. changing PREFIX).
|
||||||
srcdir = os.path.join(outdir, 'cpython')
|
srcdir = os.path.join(outdir, 'cpython')
|
||||||
git_copy_repo(srcdir, SRCDIR)
|
copy_source_tree(srcdir, SRCDIR)
|
||||||
|
|
||||||
# We use an out-of-tree build (instead of srcdir).
|
# We use an out-of-tree build (instead of srcdir).
|
||||||
builddir = os.path.join(outdir, 'python-build')
|
builddir = os.path.join(outdir, 'python-build')
|
||||||
@ -172,7 +152,7 @@ def prepare(script=None, outdir=None):
|
|||||||
raise UnsupportedError('make')
|
raise UnsupportedError('make')
|
||||||
|
|
||||||
# Build python.
|
# Build python.
|
||||||
print('building python...')
|
print(f'building python in {builddir}...')
|
||||||
if os.path.exists(os.path.join(srcdir, 'Makefile')):
|
if os.path.exists(os.path.join(srcdir, 'Makefile')):
|
||||||
# Out-of-tree builds require a clean srcdir.
|
# Out-of-tree builds require a clean srcdir.
|
||||||
_run_quiet([MAKE, '-C', srcdir, 'clean'])
|
_run_quiet([MAKE, '-C', srcdir, 'clean'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user