summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaz Muraus <tomaz@tomaz.me>2012-09-10 23:18:28 -0700
committerTomaz Muraus <tomaz@tomaz.me>2012-09-10 23:18:28 -0700
commit0943f7b5c3769bffd66532527ae7e12ec5f51b63 (patch)
tree6fdabc408e78becb9d64c55d8f8ce63e537484a5
parent063134a34d5670359c8237fe45faea0a5e72f1eb (diff)
downloadcliff-0943f7b5c3769bffd66532527ae7e12ec5f51b63.tar.gz
Add tests for new functionality.
-rw-r--r--tests/test_app.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_app.py b/tests/test_app.py
index 8bff071..7ba1588 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -1,3 +1,5 @@
+from argparse import ArgumentError
+
from cliff.app import App
from cliff.command import Command
from cliff.commandmanager import CommandManager
@@ -168,3 +170,51 @@ def test_normal_clean_up_raises_exception_debug():
app.clean_up.assert_called_once()
call_args = app.clean_up.call_args_list[0]
assert call_args == mock.call(mock.ANY, 0, None)
+
+def test_build_option_parser_conflicting_option_should_throw():
+ class MyApp(App):
+ def __init__(self):
+ super(MyApp, self).__init__(
+ description='testing',
+ version='0.1',
+ command_manager=CommandManager('tests'),
+ )
+
+ def build_option_parser(self, description, version):
+ parser = super(MyApp, self).build_option_parser(description,
+ version)
+ parser.add_argument(
+ '-h', '--help',
+ default=self, # tricky
+ help="show this help message and exit",
+ )
+
+ # TODO: tests should really use unittest2.
+ try:
+ MyApp()
+ except ArgumentError:
+ pass
+ else:
+ raise Exception('Exception was not thrown')
+
+def test_build_option_parser_conflicting_option_custom_arguments_should_not_throw():
+ class MyApp(App):
+ def __init__(self):
+ super(MyApp, self).__init__(
+ description='testing',
+ version='0.1',
+ command_manager=CommandManager('tests'),
+ )
+
+ def build_option_parser(self, description, version):
+ argparse_kwargs = {'conflict_handler': 'resolve'}
+ parser = super(MyApp, self).build_option_parser(description,
+ version,
+ argparse_kwargs=argparse_kwargs)
+ parser.add_argument(
+ '-h', '--help',
+ default=self, # tricky
+ help="show this help message and exit",
+ )
+
+ MyApp()