[Python-checkins] cpython (merge 3.2 -> 3.3): #16306: merge with 3.2.
ezio.melotti
python-checkins at python.org
Fri Nov 23 18:01:59 CET 2012
http://hg.python.org/cpython/rev/421a8a5ffbb2
changeset: 80567:421a8a5ffbb2
branch: 3.3
parent: 80563:5d1e7912e23e
parent: 80566:654a628f5f00
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Fri Nov 23 18:52:39 2012 +0200
summary:
#16306: merge with 3.2.
files:
Lib/test/test_cmd_line.py | 18 +++++++++++++++---
Modules/main.c | 1 +
Python/getopt.c | 2 +-
3 files changed, 17 insertions(+), 4 deletions(-)
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
@@ -370,12 +370,24 @@
print("del sys.modules['__main__']", file=script)
assert_python_ok(filename)
-
def test_unknown_options(self):
- rc, out, err = assert_python_failure('-z', __cleanenv=True)
- self.assertIn(b'Unknown option', err)
+ rc, out, err = assert_python_failure('-E', '-z')
+ self.assertIn(b'Unknown option: -z', err)
self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
self.assertEqual(b'', out)
+ # Add "without='-E'" to prevent _assert_python to append -E
+ # to env_vars and change the output of stderr
+ rc, out, err = assert_python_failure('-z', without='-E')
+ self.assertIn(b'Unknown option: -z', err)
+ self.assertEqual(err.splitlines().count(b'Unknown option: -z'), 1)
+ self.assertEqual(b'', out)
+ rc, out, err = assert_python_failure('-a', '-z', without='-E')
+ self.assertIn(b'Unknown option: -a', err)
+ # only the first unknown option is reported
+ self.assertNotIn(b'Unknown option: -z', err)
+ self.assertEqual(err.splitlines().count(b'Unknown option: -a'), 1)
+ self.assertEqual(b'', out)
+
def test_main():
test.support.run_unittest(CmdLineTest)
diff --git a/Modules/main.c b/Modules/main.c
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -338,6 +338,7 @@
/* Hash randomization needed early for all string operations
(including -W and -X options). */
+ _PyOS_opterr = 0; /* prevent printing the error in 1st pass */
while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
if (c == 'm' || c == 'c') {
/* -c / -m is the last option: following arguments are
diff --git a/Python/getopt.c b/Python/getopt.c
--- a/Python/getopt.c
+++ b/Python/getopt.c
@@ -45,7 +45,7 @@
void _PyOS_ResetGetOpt(void)
{
- _PyOS_opterr = 0; /* prevent printing the error in 2nd loop in main.c */
+ _PyOS_opterr = 1;
_PyOS_optind = 1;
_PyOS_optarg = NULL;
opt_ptr = L"";
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list