예제 #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 testConsolePluginNoColor(self):
        '''
        >test command
        console.color = False
        >test command --no-color
        console.color = False
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_):
            console_.Print('console.color = %s' % console_.color)

        app.Add(Command)

        app.TestScript(inspect.getdoc(self.testConsolePluginNoColor))
예제 #6
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))
예제 #7
0
    def testUnknownOptionArgs(self):
        def Command(console_):
            ''

        app = App('test', color=False, buffered_console=True)
        app.Add(Command)

        app.TestScript(
            dedent('''
            >test command --foo --bar [retcode=1]
            ERROR: Unrecognized arguments: --foo --bar

            (no description)

            Usage:
                command\s\s

            Parameters:

            Options:
            '''.replace('\s', ' ')))
예제 #8
0
    def testConsolePluginVerbosity(self):
        '''
        >test command
        quiet
        normal
        >test command --verbose
        quiet
        normal
        verbose
        >test command --quiet
        quiet
        '''
        app = App('test', color=False, buffered_console=True)

        def Command(console_):
            console_.PrintQuiet('quiet')
            console_.Print('normal')
            console_.PrintVerbose('verbose')

        app.Add(Command)

        app.TestScript(inspect.getdoc(self.testConsolePluginVerbosity))