diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-06-06 10:58:36 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-06-06 10:58:36 (GMT) |
commit | 446a25fa3ca845315259f0f491e8e3a239ff2a65 (patch) | |
tree | 3d8cea0ecdb486c6006d369fc03b587b3a38d0c6 /Lib/test/test_getopt.py | |
parent | cdbc131f0370f6e3712d4167ba987d5e6b7f2802 (diff) | |
download | cpython-446a25fa3ca845315259f0f491e8e3a239ff2a65.zip cpython-446a25fa3ca845315259f0f491e8e3a239ff2a65.tar.gz cpython-446a25fa3ca845315259f0f491e8e3a239ff2a65.tar.bz2 |
Patch 473512: add GNU style scanning as gnu_getopt.
Diffstat (limited to 'Lib/test/test_getopt.py')
-rw-r--r-- | Lib/test/test_getopt.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index f8989f1..e2ae9fe 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -4,6 +4,7 @@ import getopt from getopt import GetoptError from test_support import verify, verbose +import os def expectException(teststr, expected, failure=AssertionError): """Executes a statement passed in teststr, and raises an exception @@ -106,5 +107,24 @@ expectException( "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: print "Module getopt: tests completed successfully." |