mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
I'm only backporting the tests here.
Merged revisions 86395 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86395 | antoine.pitrou | 2010-11-10 14:55:25 +0100 (mer., 10 nov. 2010) | 4 lines Issue #10372: Import the warnings module only after the IO library is initialized, so as to avoid bootstrap issues with the '-W' option. ........
This commit is contained in:
parent
ae93389e0a
commit
9c9e1b9786
2 changed files with 56 additions and 0 deletions
|
|
@ -12,6 +12,45 @@ import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
# Executing the interpreter in a subprocess
|
# Executing the interpreter in a subprocess
|
||||||
|
def _assert_python(expected_success, *args, **env_vars):
|
||||||
|
cmd_line = [sys.executable]
|
||||||
|
if not env_vars:
|
||||||
|
cmd_line.append('-E')
|
||||||
|
cmd_line.extend(args)
|
||||||
|
# Need to preserve the original environment, for in-place testing of
|
||||||
|
# shared library builds.
|
||||||
|
env = os.environ.copy()
|
||||||
|
env.update(env_vars)
|
||||||
|
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
|
env=env)
|
||||||
|
try:
|
||||||
|
out, err = p.communicate()
|
||||||
|
finally:
|
||||||
|
subprocess._cleanup()
|
||||||
|
p.stdout.close()
|
||||||
|
p.stderr.close()
|
||||||
|
rc = p.returncode
|
||||||
|
if (rc and expected_success) or (not rc and not expected_success):
|
||||||
|
raise AssertionError(
|
||||||
|
"Process return code is %d, "
|
||||||
|
"stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
|
||||||
|
return rc, out, err
|
||||||
|
|
||||||
|
def assert_python_ok(*args, **env_vars):
|
||||||
|
"""
|
||||||
|
Assert that running the interpreter with `args` and optional environment
|
||||||
|
variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.
|
||||||
|
"""
|
||||||
|
return _assert_python(True, *args, **env_vars)
|
||||||
|
|
||||||
|
def assert_python_failure(*args, **env_vars):
|
||||||
|
"""
|
||||||
|
Assert that running the interpreter with `args` and optional environment
|
||||||
|
variables `env_vars` fails and return a (return code, stdout, stderr) tuple.
|
||||||
|
"""
|
||||||
|
return _assert_python(False, *args, **env_vars)
|
||||||
|
|
||||||
def python_exit_code(*args):
|
def python_exit_code(*args):
|
||||||
cmd_line = [sys.executable, '-E']
|
cmd_line = [sys.executable, '-E']
|
||||||
cmd_line.extend(args)
|
cmd_line.extend(args)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
import subprocess
|
import subprocess
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
from test.script_helper import assert_python_ok
|
||||||
|
|
||||||
import warning_tests
|
import warning_tests
|
||||||
|
|
||||||
|
|
@ -381,6 +382,22 @@ class WCmdLineTests(unittest.TestCase):
|
||||||
self.module._setoption('error::Warning::0')
|
self.module._setoption('error::Warning::0')
|
||||||
self.assertRaises(UserWarning, self.module.warn, 'convert to error')
|
self.assertRaises(UserWarning, self.module.warn, 'convert to error')
|
||||||
|
|
||||||
|
def test_improper_option(self):
|
||||||
|
# Same as above, but check that the message is printed out when
|
||||||
|
# the interpreter is executed. This also checks that options are
|
||||||
|
# actually parsed at all.
|
||||||
|
rc, out, err = assert_python_ok("-Wxxx", "-c", "pass")
|
||||||
|
self.assertIn(b"Invalid -W option ignored: invalid action: 'xxx'", err)
|
||||||
|
|
||||||
|
def test_warnings_bootstrap(self):
|
||||||
|
# Check that the warnings module does get loaded when -W<some option>
|
||||||
|
# is used (see issue #10372 for an example of silent bootstrap failure).
|
||||||
|
rc, out, err = assert_python_ok("-Wi", "-c",
|
||||||
|
"import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)")
|
||||||
|
# '-Wi' was observed
|
||||||
|
self.assertFalse(out.strip())
|
||||||
|
self.assertNotIn(b'RuntimeWarning', err)
|
||||||
|
|
||||||
class CWCmdLineTests(BaseTest, WCmdLineTests):
|
class CWCmdLineTests(BaseTest, WCmdLineTests):
|
||||||
module = c_warnings
|
module = c_warnings
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue