summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 17:25:23 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 17:25:23 -0400
commita531ccf8321f2ca6a707f069b07d2731409d8f38 (patch)
treedb4ac4c51869ff152f70bea9dda16f81bdb42e14
parent94c14045d62788fb123f4316867778fa5337adae (diff)
downloadcliff-tablib-a531ccf8321f2ca6a707f069b07d2731409d8f38.tar.gz
tests for cliff.help
-rw-r--r--tests/test_help.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_help.py b/tests/test_help.py
new file mode 100644
index 0000000..4a2fd1c
--- /dev/null
+++ b/tests/test_help.py
@@ -0,0 +1,75 @@
+try:
+ from StringIO import StringIO
+except:
+ from io import StringIO
+
+import mock
+
+from cliff.app import App
+from cliff.command import Command
+from cliff.commandmanager import CommandManager
+from cliff.help import HelpCommand
+
+
+class TestParser(object):
+
+ def print_help(self, stdout):
+ stdout.write('TestParser')
+
+
+class TestCommand(Command):
+
+ @classmethod
+ def load(cls):
+ return cls
+
+ def get_parser(self, ignore):
+ # Make it look like this class is the parser
+ # so parse_args() is called.
+ return TestParser()
+
+ def run(self, args):
+ return
+
+
+class TestCommandManager(CommandManager):
+ def _load_commands(self):
+ self.commands = {
+ 'one': TestCommand,
+ 'two words': TestCommand,
+ 'three word command': TestCommand,
+ }
+
+
+def test_show_help_for_command():
+ # FIXME(dhellmann): Are commands tied too closely to the app? Or
+ # do commands know too much about apps by using them to get to the
+ # command manager?
+ stdout = StringIO()
+ app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
+ app.NAME = 'test'
+ help_cmd = HelpCommand(app, mock.Mock())
+ parser = help_cmd.get_parser('test')
+ parsed_args = parser.parse_args(['one'])
+ try:
+ help_cmd.run(parsed_args)
+ except SystemExit:
+ pass
+ assert stdout.getvalue() == 'TestParser'
+
+def test_show_help_for_help():
+ # FIXME(dhellmann): Are commands tied too closely to the app? Or
+ # do commands know too much about apps by using them to get to the
+ # command manager?
+ stdout = StringIO()
+ app = App('testing', '1', TestCommandManager('cliff.test'), stdout=stdout)
+ app.NAME = 'test'
+ help_cmd = HelpCommand(app, mock.Mock())
+ parser = help_cmd.get_parser('test')
+ parsed_args = parser.parse_args([])
+ try:
+ help_cmd.run(parsed_args)
+ except SystemExit:
+ pass
+ help_text = stdout.getvalue()
+ assert 'usage: test help [-h]' in help_text