Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e8785ff8
Commit
e8785ff8
authored
Oct 12, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #18754: Run Python child processes in isolated more in the test suite.
parent
c2228c89
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
8 deletions
+27
-8
Lib/test/script_helper.py
Lib/test/script_helper.py
+17
-1
Lib/test/test_cmd_line.py
Lib/test/test_cmd_line.py
+1
-1
Lib/test/test_cmd_line_script.py
Lib/test/test_cmd_line_script.py
+6
-4
Lib/test/test_compileall.py
Lib/test/test_compileall.py
+1
-1
Lib/test/test_import.py
Lib/test/test_import.py
+2
-1
No files found.
Lib/test/script_helper.py
View file @
e8785ff8
...
...
@@ -17,8 +17,17 @@ from test.support import make_legacy_pyc, strip_python_stderr, temp_dir
# Executing the interpreter in a subprocess
def
_assert_python
(
expected_success
,
*
args
,
**
env_vars
):
if
'__isolated'
in
env_vars
:
isolated
=
env_vars
.
pop
(
'__isolated'
)
else
:
isolated
=
not
env_vars
cmd_line
=
[
sys
.
executable
,
'-X'
,
'faulthandler'
]
if
not
env_vars
:
if
isolated
:
# isolated mode: ignore Python environment variables, ignore user
# site-packages, and don't add the current directory to sys.path
cmd_line
.
append
(
'-I'
)
elif
not
env_vars
:
# ignore Python environment variables
cmd_line
.
append
(
'-E'
)
# Need to preserve the original environment, for in-place testing of
# shared library builds.
...
...
@@ -51,6 +60,11 @@ def assert_python_ok(*args, **env_vars):
Assert that running the interpreter with `args` and optional environment
variables `env_vars` succeeds (rc == 0) and return a (return code, stdout,
stderr) tuple.
If the __cleanenv keyword is set, env_vars is used a fresh environment.
Python is started in isolated mode (command line option -I),
except if the __isolated keyword is set to False.
"""
return
_assert_python
(
True
,
*
args
,
**
env_vars
)
...
...
@@ -59,6 +73,8 @@ def assert_python_failure(*args, **env_vars):
Assert that running the interpreter with `args` and optional environment
variables `env_vars` fails (rc != 0) and return a (return code, stdout,
stderr) tuple.
See assert_python_ok() for more options.
"""
return
_assert_python
(
False
,
*
args
,
**
env_vars
)
...
...
Lib/test/test_cmd_line.py
View file @
e8785ff8
...
...
@@ -263,7 +263,7 @@ class CmdLineTest(unittest.TestCase):
path = path.encode("ascii", "backslashreplace")
sys.stdout.buffer.write(path)"""
rc1
,
out1
,
err1
=
assert_python_ok
(
'-c'
,
code
,
PYTHONPATH
=
""
)
rc2
,
out2
,
err2
=
assert_python_ok
(
'-c'
,
code
)
rc2
,
out2
,
err2
=
assert_python_ok
(
'-c'
,
code
,
__isolated
=
False
)
# regarding to Posix specification, outputs should be equal
# for empty and unset PYTHONPATH
self
.
assertEqual
(
out1
,
out2
)
...
...
Lib/test/test_cmd_line_script.py
View file @
e8785ff8
...
...
@@ -123,7 +123,7 @@ class CmdLineTest(unittest.TestCase):
if
not
__debug__
:
cmd_line_switches
+=
(
'-'
+
'O'
*
sys
.
flags
.
optimize
,)
run_args
=
cmd_line_switches
+
(
script_name
,)
+
tuple
(
example_args
)
rc
,
out
,
err
=
assert_python_ok
(
*
run_args
)
rc
,
out
,
err
=
assert_python_ok
(
*
run_args
,
__isolated
=
False
)
self
.
_check_output
(
script_name
,
rc
,
out
+
err
,
expected_file
,
expected_argv0
,
expected_path0
,
expected_package
,
expected_loader
)
...
...
@@ -294,7 +294,7 @@ class CmdLineTest(unittest.TestCase):
pkg_dir
=
os
.
path
.
join
(
script_dir
,
'test_pkg'
)
make_pkg
(
pkg_dir
,
"import sys; print('init_argv0==%r' % sys.argv[0])"
)
script_name
=
_make_test_script
(
pkg_dir
,
'script'
)
rc
,
out
,
err
=
assert_python_ok
(
'-m'
,
'test_pkg.script'
,
*
example_args
)
rc
,
out
,
err
=
assert_python_ok
(
'-m'
,
'test_pkg.script'
,
*
example_args
,
__isolated
=
False
)
if
verbose
>
1
:
print
(
out
)
expected
=
"init_argv0==%r"
%
'-m'
...
...
@@ -311,7 +311,8 @@ class CmdLineTest(unittest.TestCase):
with
open
(
"-c"
,
"w"
)
as
f
:
f
.
write
(
"data"
)
rc
,
out
,
err
=
assert_python_ok
(
'-c'
,
'import sys; print("sys.path[0]==%r" % sys.path[0])'
)
'import sys; print("sys.path[0]==%r" % sys.path[0])'
,
__isolated
=
False
)
if
verbose
>
1
:
print
(
out
)
expected
=
"sys.path[0]==%r"
%
''
...
...
@@ -325,7 +326,8 @@ class CmdLineTest(unittest.TestCase):
with
support
.
change_cwd
(
path
=
script_dir
):
with
open
(
"-m"
,
"w"
)
as
f
:
f
.
write
(
"data"
)
rc
,
out
,
err
=
assert_python_ok
(
'-m'
,
'other'
,
*
example_args
)
rc
,
out
,
err
=
assert_python_ok
(
'-m'
,
'other'
,
*
example_args
,
__isolated
=
False
)
self
.
_check_output
(
script_name
,
rc
,
out
,
script_name
,
script_name
,
''
,
''
,
importlib
.
machinery
.
SourceFileLoader
)
...
...
Lib/test/test_compileall.py
View file @
e8785ff8
...
...
@@ -295,7 +295,7 @@ class CommandLineTests(unittest.TestCase):
pyc
=
importlib
.
util
.
cache_from_source
(
bazfn
)
os
.
rename
(
pyc
,
os
.
path
.
join
(
self
.
pkgdir
,
'baz.pyc'
))
os
.
remove
(
bazfn
)
rc
,
out
,
err
=
script_helper
.
assert_python_failure
(
fn
)
rc
,
out
,
err
=
script_helper
.
assert_python_failure
(
fn
,
__isolated
=
False
)
self
.
assertRegex
(
err
,
b'File "dinsdale'
)
def
test_include_bad_file
(
self
):
...
...
Lib/test/test_import.py
View file @
e8785ff8
...
...
@@ -1058,7 +1058,8 @@ class ImportTracebackTests(unittest.TestCase):
# encode filenames, especially on Windows
pyname
=
script_helper
.
make_script
(
''
,
TESTFN_UNENCODABLE
,
'pass'
)
name
=
pyname
[:
-
3
]
script_helper
.
assert_python_ok
(
"-c"
,
"mod = __import__(%a)"
%
name
)
script_helper
.
assert_python_ok
(
"-c"
,
"mod = __import__(%a)"
%
name
,
__isolated
=
False
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment