Пример #1
0
 def test_version(self):
     """Test CommandDispatcher show version"""
     sys.argv = ['testprog', '--version']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     c.main()
     out = sys.stdout.getvalue()
     self.assertEqual("testprog testver\n", out)
Пример #2
0
 def test_show_help(self):
     """Test CommandDispatcher show help"""
     for arg in ('help', '--help', '-h'):
         sys.argv = ['testprog', arg]
         c = IMP.CommandDispatcher("short", "long", "TestModule")
         c.main()
         self.assert_help_out_ok()
Пример #3
0
 def test_unknown_command(self):
     """Test CommandDispatcher unknown command"""
     sys.argv = ['testprog', 'garbage']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     self.assertRaises(SystemExit, c.main)
     out = sys.stdout.getvalue()
     self.assertIn("Unknown command: 'garbage'", out)
Пример #4
0
 def test_no_args(self):
     """Test CommandDispatcher run with no arguments"""
     sys.argv = ['testprog']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     c.main()
     out = sys.stdout.getvalue()
     self.assertIn("short Use 'testprog help' for help.", out)
Пример #5
0
 def test_show_command_help(self):
     """Test CommandDispatcher show command help ok"""
     sys.argv = ['testprog', 'help', 'bar']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     TestModule.bar_main_called = False
     c.main()
     self.assertTrue(TestModule.bar_main_called)
     self.assertEqual(sys.argv, ['testprog bar', '--help'])
Пример #6
0
 def test_do_command(self):
     """Test CommandDispatcher do command"""
     sys.argv = ['testprog', 'bar', 'arg1', 'arg2']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     TestModule.bar_main_called = False
     c.main()
     self.assertTrue(TestModule.bar_main_called)
     self.assertEqual(sys.argv, ['testprog bar', 'arg1', 'arg2'])
Пример #7
0
 def test_import_module(self):
     """Test CommandDispatcher.import_module()"""
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     self.assertEqual(id(c.import_module()), id(TestModule))
     self.assertEqual(id(c.import_module('submodule')),
                      id(TestModule.submodule))
Пример #8
0
 def test_init(self):
     """Test CommandDispatcher init"""
     sys.argv = ['/foo/bar/testprogname', 'arg1']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     self.assertEqual(c._progname, 'testprogname')
Пример #9
0
 def test_show_command_help_help(self):
     """Test CommandDispatcher show help command help"""
     sys.argv = ['testprog', 'help', 'help']
     c = IMP.CommandDispatcher("short", "long", "TestModule")
     c.main()
     self.assert_help_out_ok()