예제 #1
0
파일: tests.py 프로젝트: everbird/komandr
    def testOptionsNotTriggerDefaultSubcommand(self):
        def foo(baz='bar'):
            return baz
        komandr.command(foo)

        komandr.main.default_subcommand = 'foo'
        with patch.object(komandr.main.parser, 'print_help') as mock:
            with self.assertRaises(SystemExit) as ex:
                komandr.execute(['--help'])

        self.assertEqual(0, ex.exception.code)
        self.assertTrue(mock.called)

        self.assertEqual('bar baz', komandr.execute(['--baz', 'bar baz']))
예제 #2
0
파일: tests.py 프로젝트: everbird/komandr
    def testDefaultSubcommand(self):
        def foo(bar, baz=None):
            return bar, baz
        komandr.command(foo)

        # Without main.default_subcommand a `SystemExit` exception would raise.
        with self.assertRaises(SystemExit) as ex:
            komandr.execute([])

        self.assertEqual(2, ex.exception.code)

        # With main.default_subcommand='foo', subcommand named `foo` would be
        # called by default when no subcommand.
        komandr.main.default_subcommand = 'foo'
        self.assertEqual(('1', '2'), komandr.execute(['1', '--baz', '2']))
예제 #3
0
파일: tests.py 프로젝트: everbird/komandr
    def testDefaultSubcommandWithoutOptions(self):
        def foo():
            return 'bar'
        komandr.command(foo)

        komandr.main.default_subcommand = 'foo'
        self.assertEqual('bar', komandr.execute([]))
예제 #4
0
    def testCommand(self):
        def foo(bar, baz=None):
            return bar, baz

        komandr.command(foo)
        self.assertEqual(('1', '2'),
                         komandr.execute(['foo', '1', '--baz', '2']))
예제 #5
0
 def testCommand(self):
     def foo(bar, baz=None):
         return bar, baz
     komandr.command(foo)
     self.assertEqual(('1', '2'),
                      komandr.execute(['foo', '1', '--baz', '2']))