[Python-checkins] cpython (merge 3.5 -> default): * Re-fix issue #19284: Don't generate the no-op -R command line
gregory.p.smith
python-checkins at python.org
Sun Dec 13 23:15:42 EST 2015
https://hg.python.org/cpython/rev/41717421b134
changeset: 99569:41717421b134
parent: 99563:7309be384c6a
parent: 99568:014e6f7d7c1a
user: Gregory P. Smith <greg at krypto.org>
date: Sun Dec 13 20:15:26 2015 -0800
summary:
* Re-fix issue #19284: Don't generate the no-op -R command line
parameter to "enable" the always on sys.flags.hash_randomization
in _args_from_interpreter_flags() used by multiprocessing and
some unittests. This simplifies the code.
* assert_python_ok docstring typo fix.
* Fix test_cmd_line not to fail if PYTHONHASHSEED is set to a fixed seed.
files:
Lib/subprocess.py | 3 ---
Lib/test/support/script_helper.py | 2 +-
Lib/test/test_cmd_line.py | 18 +++++++++++++++---
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -535,14 +535,11 @@
'verbose': 'v',
'bytes_warning': 'b',
'quiet': 'q',
- 'hash_randomization': 'R',
}
args = []
for flag, opt in flag_opt_map.items():
v = getattr(sys.flags, flag)
if v > 0:
- if flag == 'hash_randomization':
- v = 1 # Handle specification of an exact seed
args.append('-' + opt * v)
for opt in sys.warnoptions:
args.append('-W' + opt)
diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py
--- a/Lib/test/support/script_helper.py
+++ b/Lib/test/support/script_helper.py
@@ -127,7 +127,7 @@
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.
+ If the __cleanenv keyword is set, env_vars is used as a fresh environment.
Python is started in isolated mode (command line option -I),
except if the __isolated keyword is set to False.
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -404,12 +404,24 @@
# Verify that -R enables hash randomization:
self.verify_valid_flag('-R')
hashes = []
- for i in range(2):
+ if os.environ.get('PYTHONHASHSEED', 'random') != 'random':
+ env = dict(os.environ) # copy
+ # We need to test that it is enabled by default without
+ # the environment variable enabling it for us.
+ del env['PYTHONHASHSEED']
+ env['__cleanenv'] = '1' # consumed by assert_python_ok()
+ else:
+ env = {}
+ for i in range(3):
code = 'print(hash("spam"))'
- rc, out, err = assert_python_ok('-c', code)
+ rc, out, err = assert_python_ok('-c', code, **env)
self.assertEqual(rc, 0)
hashes.append(out)
- self.assertNotEqual(hashes[0], hashes[1])
+ hashes = sorted(set(hashes)) # uniq
+ # Rare chance of failure due to 3 random seeds honestly being equal.
+ self.assertGreater(len(hashes), 1,
+ msg='3 runs produced an identical random hash '
+ ' for "spam": {}'.format(hashes))
# Verify that sys.flags contains hash_randomization
code = 'import sys; print("random is", sys.flags.hash_randomization)'
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list