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))
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))
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))
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))
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))
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', ' ')))