Commits

bewest committed 938e1e9

incorrect regexp

There's a test in
git@gist.github.com:1202975.git
http://gist.github.com/1202975
* test_opt_subcommand.py
* s.py

That gives this error:

bewest@ripen:~/Documents/git/gist/cli-hello$ python test_opt_subcommand.py -v
test_optional_subcommand_behavior (__main__.TestSubparserDefaultFun) ... ['add subparsers',
<class 'argparse._SubParsersAction'>,
{'default': 'qux',
'dest': 'command',
'help': 'some help on group A',
'parser_class': <class 'argparse.ArgumentParser'>,
'prog': 'my program'}]
['consume optionals']
['remaining positionals',
[_SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None)]]
([-AO]*) A?..
['match arguments partial', '([-AO]*)', <_sre.SRE_Match object at 0x93f34a0>]
['consume positionals',
{'arg_counts': [0],
'arg_strings': [],
'arg_strings_pattern': '',
'match_partial': <bound method ArgumentParser._match_arguments_partial of ArgumentParser(prog='test_opt_subcommand.py', usage=None, description=None, version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)>,
'positionals': [_SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None)],
'selected_pattern': '',
'self': ArgumentParser(prog='test_opt_subcommand.py', usage=None, description=None, version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True),
'start_index': 0,
'take_action': <function take_action at 0x95c1a04>}]
['loop',
_SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None),
0]
['get values',
_SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None),
[]]
['VALUE', 'qux']
['take action',
_SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None),
[]]
['select parser',
{'arg_strings': 'ux',
'namespace': Namespace(command='q', debug=False),
'option_string': None,
'parser': ArgumentParser(prog='test_opt_subcommand.py', usage=None, description=None, version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True),
'parser_name': 'q',
'self': _SubParsersAction(option_strings=[], dest='command', nargs='A?..', const=None, default='qux', type=None, choices={'lux': ArgumentParser(prog='my program lux', usage=None, description='long desc of lux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'qux': ArgumentParser(prog='my program qux', usage=None, description='long desc of qux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'bux': ArgumentParser(prog='my program bux', usage=None, description='long desc of bux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'fux': ArgumentParser(prog='my program fux', usage=None, description='long desc of fux', version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, help='some help on group A', metavar=None),
'values': 'qux'}]
usage: test_opt_subcommand.py [-h] [-d] {lux,qux,bux,fux} ...
test_opt_subcommand.py: error: argument command: unknown parser 'q' (choices: lux, qux, bux, fux)
ERROR

======================================================================
ERROR: test_optional_subcommand_behavior (__main__.TestSubparserDefaultFun)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_opt_subcommand.py", line 32, in test_optional_subcommand_behavior
self.parser.parse_args(prep(' '))
File "/home/bewest/Documents/git/argparse/argparse.py", line 1715, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/home/bewest/Documents/git/argparse/argparse.py", line 1754, in parse_known_args
self.error(str(err))
File "/home/bewest/Documents/git/argparse/argparse.py", line 2398, in error
self.exit(2, _('%s: error: %s\n') % (self.prog, message))
File "/home/bewest/Documents/git/argparse/argparse.py", line 2386, in exit
_sys.exit(status)
SystemExit: 2

----------------------------------------------------------------------
Ran 1 test in 0.013s

FAILED (errors=1)
bewest@ripen:~/Documents/git/gist/cli-hello$ git diff
bewest@ripen:~/Documents/git/gist/cli-hello$ git remote
origin
bewest@ripen:~/Documents/git/gist/cli-hello$ git remote
add prune rename rm set-head show update
bewest@ripen:~/Documents/git/gist/cli-hello$ git remote show -v
error: unknown switch `v'
usage: git remote show [<options>] <name>

-n do not query remotes

bewest@ripen:~/Documents/git/gist/cli-hello$ git remote -v
origin git@gist.github.com:1202975.git (fetch)
origin git@gist.github.com:1202975.git (push)
bewest@ripen:~/Documents/git/gist/cli-hello$ j^C
bewest@ripen:~/Documents/git/gist/cli-hello$ jobs
bewest@ripen:~/Documents/git/gist/cli-hello$ ls
a.py a.pyc b.py b.pyc README s.py test_opt_subcommand.py
bewest@ripen:~/Documents/git/gist/cli-hello$

  • Participants
  • Parent commits 361962c

Comments (0)

Files changed (1)

         # arguments
         elif nargs == _OPTIONAL_PARSER:
             # XXX.bewest: This doesn't quite work.
-            nargs_pattern = '(-*A?-[-AO]*)?'
+            nargs_pattern = '(-*A[-AO]*)|([-AO]*)'
+            #nargs_pattern = '([-*A]?-[-AO]*)?'
+            #nargs_pattern = '([-AO]*)'
             nargs_pattern = '([-AO]*)'
 
         # all others should be integers