Skip to content

Commit

Permalink
Added tests for preparsing bugs in piranhaGH-23
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbenjamin committed Apr 26, 2012
1 parent 156c5fd commit 4ad0b6e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/multicommands.py
Expand Up @@ -81,10 +81,12 @@ def __init__(self, verbose=False, quiet=False):
def write(self, *messages):
for m in messages:
sys.stdout.write(m)
sys.stdout.flush()

def warn(self, *messages):
for m in messages:
sys.stderr.write(m)
sys.stderr.flush()

info = lambda self, *m: not self.quiet and self.write(*m)
note = lambda self, *m: self.verbose and self.write(*m)
Expand Down
86 changes: 86 additions & 0 deletions tests/opster.t
Expand Up @@ -106,6 +106,69 @@ Check if integer errors correctly::
-q --quiet suppress output
-h --help display help

Opster can parse non-global options after the command argument::

$ run multicommands.py complex --name dave
write
info
warn
[100]

We also get the right command when using --opt=value syntax::

$ run multicommands.py complex --name=dave
write
info
warn
[100]

Global options can appear before the command argument.

$ run multicommands.py --quiet complex
write
warn
[100]

However, non-global options before the command argument are not allowed::

$ run multicommands.py --name=dave complex
error: option --name not recognized
usage: multicommands.py <command> [options]
commands:
help Show help for a given help topic or a help overview.
nodoc (no help text available)
simple Just simple command to print keys of received arguments.

regardless of which syntax you use::

$ run multicommands.py --name dave complex
error: option --name not recognized
usage: multicommands.py <command> [options]
commands:
help Show help for a given help topic or a help overview.
nodoc (no help text available)
simple Just simple command to print keys of received arguments.

Opster won't accidentally run the simple command because you tried to pass
simple as an argument to the --name option::

$ run multicommands.py --name simple complex
error: option --name not recognized
usage: multicommands.py <command> [options]
commands:
help Show help for a given help topic or a help overview.
nodoc (no help text available)
simple Just simple command to print keys of received arguments.

We also have completion::

$ run multicommands.py _completion
Expand Down Expand Up @@ -165,6 +228,29 @@ Now let's test our definitions::
'port': 8000,
'test': 'test'}

As long as only the last option has a parameter We can combine short options
into one argument::

$ run test_opts.py -dDa=b so-what?
{'daemonize': True,
'definitions': {'a': 'b'},
'dirname': 'so-what?',
'listen': 'localhost',
'pid_file': '',
'port': 8000,
'test': 'test'}

The parameter can be in a separate argument::

$ run test_opts.py -dD a=b so-what?
{'daemonize': True,
'definitions': {'a': 'b'},
'dirname': 'so-what?',
'listen': 'localhost',
'pid_file': '',
'port': 8000,
'test': 'test'}

$ run test_opts.py -D can-i-haz fail?
error: wrong definition: 'can-i-haz' (should be in format KEY=VALUE)
Expand Down

0 comments on commit 4ad0b6e

Please sign in to comment.