示例#1
0
    def testPositionalArgs(self):
        '''
        >test command alpha bravo
        alpha..bravo
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_, first, second):
            console_.Print('%s..%s' % (first, second))

        app.Add(Command)

        app.TestScript(inspect.getdoc(self.testPositionalArgs))
示例#2
0
    def testBoolArgFalse(self):
        '''
        >test command
        False
        >test command --option
        True
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_, option=False):
            console_.Print(option)

        app.Add(Command)
        app.TestScript(inspect.getdoc(self.testBoolArgFalse))
示例#3
0
    def testOptionUnderscore(self):
        '''
        >test command
        my_option = default
        >test command --my-option=custom
        my_option = custom
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_, my_option='default'):
            console_.Print('my_option = ' + my_option)

        app.Add(Command)

        app.TestScript(inspect.getdoc(self.testOptionUnderscore))
示例#4
0
    def testOptionArgs(self):
        '''
        >test command
        1..2
        >test command --first=alpha --second=bravo
        alpha..bravo
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_, first='1', second='2'):
            console_.Print('%s..%s' % (first, second))

        app.Add(Command)

        app.TestScript(inspect.getdoc(self.testOptionArgs))
示例#5
0
    def testPositionalArgsWithDefaults(self):
        '''
        >test hello
        NOTHING

        >test hello something
        something
        '''
        app = App('test', color=False, buffered_console=True)

        def Hello(console_, message=App.DEFAULT('NOTHING')):
            console_.Print(message)

        app.Add(Hello)

        app.TestScript(inspect.getdoc(self.testPositionalArgsWithDefaults))
示例#6
0
    def testUnknownOptionArgs(self):
        app = App('test', color=False, buffered_console=True)

        def Command(console_):
            console_.Print('hello')

        app.Add(Command)

        app.TestScript(
            Dedent('''
            >test command --foo --bar
            ERROR: Unrecognized arguments: --foo --bar

            (no description)

            Usage:
                command\s\s

            Parameters:

            Options:
            '''.replace('\s', ' ')))