# HG changeset patch # User John Mulligan # Date 1257113360 18000 # Sun Nov 01 17:09:20 2009 -0500 # Node ID 3e309b038e01ad8df371c256af5693c53517bdfc # Parent 625e05b49e500afbb96fa7ca9c4353b003c82569 commander: more tests for help behavior diff --git a/test/test_cli_commands.py b/test/test_cli_commands.py --- a/test/test_cli_commands.py +++ b/test/test_cli_commands.py @@ -187,13 +187,6 @@ self.assert_('baz' in usage) def test_fancy_help_3(self): - def tst(arguments): - capture = Capture() - try: - result = commander.launch(GOPT_A, CMDTABLE_A, arguments) - except commander.HelpWanted, herr: - commander.handlehelp(herr, GOPT_A, CMDTABLE_A, output=capture) - return ''.join(capture) c1 = tst('foo --help'.split()) c2 = tst('foo -h'.split()) c3 = tst('--help foo'.split()) @@ -208,6 +201,11 @@ self.assertEqual(c1, c2) self.assertEqual(c2, c3) + def test_fancy_help_4(self): + self.assertRaises(commander.MissingCommand, tst, []) + tst('help zork'.split()) + self.assertRaises(commander.InvalidCommand, tst, 'zork -h'.split()) + class Capture(list): @@ -215,5 +213,14 @@ self.append(x) +def tst(arguments): + capture = Capture() + try: + result = commander.launch(GOPT_A, CMDTABLE_A, arguments) + except commander.HelpWanted, herr: + commander.handlehelp(herr, GOPT_A, CMDTABLE_A, output=capture) + return ''.join(capture) + + if __name__ == '__main__': unittest.main()