[Python-checkins] python/dist/src/Lib/test test_getopt.py,1.4,1.5
loewis@users.sourceforge.net
loewis@users.sourceforge.net
Thu, 06 Jun 2002 03:58:38 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv9636/Lib/test
Modified Files:
test_getopt.py
Log Message:
Patch 473512: add GNU style scanning as gnu_getopt.
Index: test_getopt.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_getopt.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_getopt.py 17 Jan 2001 19:11:13 -0000 1.4
--- test_getopt.py 6 Jun 2002 10:58:36 -0000 1.5
***************
*** 5,8 ****
--- 5,9 ----
from getopt import GetoptError
from test_support import verify, verbose
+ import os
def expectException(teststr, expected, failure=AssertionError):
***************
*** 106,109 ****
--- 107,129 ----
"opts, args = getopt.getopt(cmdline, 'a:b', ['alpha', 'beta'])",
GetoptError)
+
+ # Test handling of GNU style scanning mode.
+ if verbose:
+ print 'Running tests on getopt.gnu_getopt'
+ cmdline = ['-a', 'arg1', '-b', '1', '--alpha', '--beta=2']
+ # GNU style
+ opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
+ verify(opts == [('-a', ''), ('-b', '1'), ('--alpha', ''), ('--beta', '2')])
+ verify(args == ['arg1'])
+ # Posix style via +
+ opts, args = getopt.gnu_getopt(cmdline, '+ab:', ['alpha', 'beta='])
+ verify(opts == [('-a', '')])
+ verify(args == ['arg1', '-b', '1', '--alpha', '--beta=2'])
+ # Posix style via POSIXLY_CORRECT
+ os.environ["POSIXLY_CORRECT"] = "1"
+ opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
+ verify(opts == [('-a', '')])
+ verify(args == ['arg1', '-b', '1', '--alpha', '--beta=2'])
+
if verbose: