mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
Issue #9517: Move script_helper to the support package.
Patch by Christie Wilson.
This commit is contained in:
parent
025e9ebd0a
commit
ce643913a9
45 changed files with 115 additions and 102 deletions
|
@ -13,10 +13,9 @@ import subprocess
|
|||
|
||||
import textwrap
|
||||
from test import support
|
||||
from test.script_helper import (
|
||||
from test.support.script_helper import (
|
||||
make_pkg, make_script, make_zip_pkg, make_zip_script,
|
||||
assert_python_ok, assert_python_failure, temp_dir,
|
||||
spawn_python, kill_python)
|
||||
assert_python_ok, assert_python_failure, spawn_python, kill_python)
|
||||
|
||||
verbose = support.verbose
|
||||
|
||||
|
@ -223,14 +222,14 @@ class CmdLineTest(unittest.TestCase):
|
|||
self.check_repl_stderr_flush(True)
|
||||
|
||||
def test_basic_script(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script')
|
||||
self._check_script(script_name, script_name, script_name,
|
||||
script_dir, None,
|
||||
importlib.machinery.SourceFileLoader)
|
||||
|
||||
def test_script_compiled(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script')
|
||||
py_compile.compile(script_name, doraise=True)
|
||||
os.remove(script_name)
|
||||
|
@ -240,14 +239,14 @@ class CmdLineTest(unittest.TestCase):
|
|||
importlib.machinery.SourcelessFileLoader)
|
||||
|
||||
def test_directory(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, '__main__')
|
||||
self._check_script(script_dir, script_name, script_dir,
|
||||
script_dir, '',
|
||||
importlib.machinery.SourceFileLoader)
|
||||
|
||||
def test_directory_compiled(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, '__main__')
|
||||
py_compile.compile(script_name, doraise=True)
|
||||
os.remove(script_name)
|
||||
|
@ -257,19 +256,19 @@ class CmdLineTest(unittest.TestCase):
|
|||
importlib.machinery.SourcelessFileLoader)
|
||||
|
||||
def test_directory_error(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
msg = "can't find '__main__' module in %r" % script_dir
|
||||
self._check_import_error(script_dir, msg)
|
||||
|
||||
def test_zipfile(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, '__main__')
|
||||
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
|
||||
self._check_script(zip_name, run_name, zip_name, zip_name, '',
|
||||
zipimport.zipimporter)
|
||||
|
||||
def test_zipfile_compiled(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, '__main__')
|
||||
compiled_name = py_compile.compile(script_name, doraise=True)
|
||||
zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name)
|
||||
|
@ -277,14 +276,14 @@ class CmdLineTest(unittest.TestCase):
|
|||
zipimport.zipimporter)
|
||||
|
||||
def test_zipfile_error(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'not_main')
|
||||
zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name)
|
||||
msg = "can't find '__main__' module in %r" % zip_name
|
||||
self._check_import_error(zip_name, msg)
|
||||
|
||||
def test_module_in_package(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
script_name = _make_test_script(pkg_dir, 'script')
|
||||
|
@ -294,14 +293,14 @@ class CmdLineTest(unittest.TestCase):
|
|||
importlib.machinery.SourceFileLoader)
|
||||
|
||||
def test_module_in_package_in_zipfile(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script')
|
||||
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name)
|
||||
self._check_script(launch_name, run_name, run_name,
|
||||
zip_name, 'test_pkg', zipimport.zipimporter)
|
||||
|
||||
def test_module_in_subpackage_in_zipfile(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2)
|
||||
launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name)
|
||||
self._check_script(launch_name, run_name, run_name,
|
||||
|
@ -309,7 +308,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
zipimport.zipimporter)
|
||||
|
||||
def test_package(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
script_name = _make_test_script(pkg_dir, '__main__')
|
||||
|
@ -319,7 +318,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
importlib.machinery.SourceFileLoader)
|
||||
|
||||
def test_package_compiled(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
script_name = _make_test_script(pkg_dir, '__main__')
|
||||
|
@ -332,7 +331,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
importlib.machinery.SourcelessFileLoader)
|
||||
|
||||
def test_package_error(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
msg = ("'test_pkg' is a package and cannot "
|
||||
|
@ -341,7 +340,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
self._check_import_error(launch_name, msg)
|
||||
|
||||
def test_package_recursion(self):
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
main_dir = os.path.join(pkg_dir, '__main__')
|
||||
|
@ -355,7 +354,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
def test_issue8202(self):
|
||||
# Make sure package __init__ modules see "-m" in sys.argv0 while
|
||||
# searching for the module to execute
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
with support.change_cwd(path=script_dir):
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])")
|
||||
|
@ -372,7 +371,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
def test_issue8202_dash_c_file_ignored(self):
|
||||
# Make sure a "-c" file in the current directory
|
||||
# does not alter the value of sys.path[0]
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
with support.change_cwd(path=script_dir):
|
||||
with open("-c", "w") as f:
|
||||
f.write("data")
|
||||
|
@ -387,7 +386,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
def test_issue8202_dash_m_file_ignored(self):
|
||||
# Make sure a "-m" file in the current directory
|
||||
# does not alter the value of sys.path[0]
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'other')
|
||||
with support.change_cwd(path=script_dir):
|
||||
with open("-m", "w") as f:
|
||||
|
@ -402,7 +401,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
# If a module is invoked with the -m command line flag
|
||||
# and results in an error that the return code to the
|
||||
# shell is '1'
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
with support.change_cwd(path=script_dir):
|
||||
pkg_dir = os.path.join(script_dir, 'test_pkg')
|
||||
make_pkg(pkg_dir)
|
||||
|
@ -422,7 +421,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
except:
|
||||
raise NameError from None
|
||||
""")
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
text = stderr.decode('ascii').split('\n')
|
||||
|
@ -466,7 +465,7 @@ class CmdLineTest(unittest.TestCase):
|
|||
if error:
|
||||
sys.exit(error)
|
||||
""")
|
||||
with temp_dir() as script_dir:
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
text = stderr.decode('ascii')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue