mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Patch 473512: add GNU style scanning as gnu_getopt.
This commit is contained in:
parent
cdbc131f03
commit
446a25fa3c
5 changed files with 103 additions and 2 deletions
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue