コード例 #1
0
class TestCase(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.commandOption = Option("command-option", "A command option")
        self.commandOptionActivate = self.mocks.create("commandOptionActivate")
        self.commandOption.activate = self.commandOptionActivate.object

        self.programOption = Option("program-option", "A program option")
        self.programOptionActivate = self.mocks.create("programOptionActivate")
        self.programOption.activate = self.programOptionActivate.object
        self.programOptionDeactivate = self.mocks.create("programOptionDeactivate")
        self.programOption.deactivate = self.programOptionDeactivate.object

        self.command = Command("test", "A test command")
        self.command.addOption(self.commandOption)
        self.commandExecute = self.mocks.create("commandExecute")
        self.command.execute = self.commandExecute.object

        self.program = Program("program", self.input.object, self.output.object)
        self.program.addCommand(self.command)
        self.program.addOption(self.programOption)

    def tearDown(self):
        self.mocks.tearDown()
コード例 #2
0
class AutoHelpWithoutOptions(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.command = Command("test", "A test command")

        self.program = Program("example", self.input.object, self.output.object)
        self.program.addCommand(self.command)

    def tearDown(self):
        self.mocks.tearDown()

    def testCommandLineProgramHelp(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  example command [options]
          Interactive mode:   example

        Commands:
          help  Display this help message
          test  A test command
        """))
        self.program._execute("help")

    def testCommandLineCommandHelp(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  example test
          Interactive mode:   test
        """))
        self.program._execute("help", "test")
コード例 #3
0
class TestCase(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.commandOption = Option("command-option", "A command option")
        self.commandOptionActivate = self.mocks.create("commandOptionActivate")
        self.commandOption.activate = self.commandOptionActivate.object

        self.programOption = Option("program-option", "A program option")
        self.programOptionActivate = self.mocks.create("programOptionActivate")
        self.programOption.activate = self.programOptionActivate.object
        self.programOptionDeactivate = self.mocks.create("programOptionDeactivate")
        self.programOption.deactivate = self.programOptionDeactivate.object

        self.command = Command("test", "A test command")
        self.command.addOption(self.commandOption)
        self.commandExecute = self.mocks.create("commandExecute")
        self.command.execute = self.commandExecute.object

        self.program = Program("program", self.input.object, self.output.object)
        self.program.addCommand(self.command)
        self.program.addOption(self.programOption)

    def tearDown(self):
        self.mocks.tearDown()
コード例 #4
0
class AutoHelpWithOptions(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.commandOption = Option("command-option", "A command option")

        self.programOption = Option("program-option", "A program option")
        self.storingOption = StoringOption("storing-option", "A storing option", None, None, ConstantValue(True), ConstantValue(False))

        self.command = Command("test", "A test command")
        self.command.addOption(self.commandOption)

        self.program = Program("example", self.input.object, self.output.object)
        self.program.addCommand(self.command)
        self.program.addOption(self.programOption)
        self.program.addOption(self.storingOption)

    def tearDown(self):
        self.mocks.tearDown()

    def testCommandLineProgramHelp(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  example [global-options] command [options]
          Interactive mode:   example [global-options]

        Global options:
          --program-option  A program option
          --storing-option  A storing option

        Commands:
          help  Display this help message
          test  A test command
        """))
        self.program._execute("help")

    def testCommandLineCommandHelp(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  example [global-options] test [test-options]
          Interactive mode:   test [test-options]

        Global options:
          --program-option  A program option
          --storing-option  A storing option

        Options of command 'test':
          --command-option  A command option
        """))
        self.program._execute("help", "test")
コード例 #5
0
class SuperCommandTestCase(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.superCommand = SuperCommand("foo", "a super command")

        self.subCommand = Command("bar", "barbaz a frobnicator")
        self.subCommandExecute = self.mocks.create("subCommandExecute")
        self.subCommand.execute = self.subCommandExecute.object
        self.superCommand.addCommand(self.subCommand)

        self.subCommandOption = Option("sub-command-option", "A sub-command option")
        self.subCommandOptionActivate = self.mocks.create("subCommandOptionActivate")
        self.subCommandOption.activate = self.subCommandOptionActivate.object
        self.subCommand.addOption(self.subCommandOption)

        self.superCommandOption = Option("super-command-option", "A super-command option")
        self.superCommandOptionActivate = self.mocks.create("superCommandOptionActivate")
        self.superCommandOption.activate = self.superCommandOptionActivate.object
        self.superCommand.addOption(self.superCommandOption)

        self.program = Program("program", self.input.object, self.output.object)
        self.program.addCommand(self.superCommand)

    def tearDown(self):
        self.mocks.tearDown()

    def testExecute(self):
        self.subCommandExecute.expect()
        self.program._execute("foo", "bar")

    def testExecuteWithSuperCommandOption(self):
        self.superCommandOptionActivate.expect("bar").andReturn(["bar"])
        self.subCommandExecute.expect()
        self.program._execute("foo", "--super-command-option", "bar")

    def testExecuteWithSubCommandOption(self):
        self.subCommandOptionActivate.expect().andReturn([])
        self.subCommandExecute.expect()
        self.program._execute("foo", "bar", "--sub-command-option")

    def testDoc(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program command [options]
          Interactive mode:   program

        Commands:
          help  Display this help message
          foo   a super command
        """))
        self.program._execute("help")

    def testDocOfSuperCommand(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program foo [foo-options] sub-command [options]
          Interactive mode:   foo [foo-options] sub-command [options]

        Options of command 'foo':
          --super-command-option  A super-command option

        Sub-commands:
          bar  barbaz a frobnicator
        """))
        self.program._execute("help", "foo")

    def testDocOfSubCommand(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program foo [foo-options] bar [bar-options]
          Interactive mode:   foo [foo-options] bar [bar-options]

        Options of command 'foo':
          --super-command-option  A super-command option

        Options of command 'bar':
          --sub-command-option  A sub-command option
        """))
        self.program._execute("help", "foo", "bar")
コード例 #6
0
class SuperCommandTestCase(unittest.TestCase):
    def setUp(self):
        self.mocks = MockMockMock.Engine()
        self.input = self.mocks.create("input")
        self.output = self.mocks.create("output")

        self.superCommand = SuperCommand("foo", "a super command")

        self.subCommand = Command("bar", "barbaz a frobnicator")
        self.subCommandExecute = self.mocks.create("subCommandExecute")
        self.subCommand.execute = self.subCommandExecute.object
        self.superCommand.addCommand(self.subCommand)

        self.subCommandOption = Option("sub-command-option", "A sub-command option")
        self.subCommandOptionActivate = self.mocks.create("subCommandOptionActivate")
        self.subCommandOption.activate = self.subCommandOptionActivate.object
        self.subCommand.addOption(self.subCommandOption)

        self.superCommandOption = Option("super-command-option", "A super-command option")
        self.superCommandOptionActivate = self.mocks.create("superCommandOptionActivate")
        self.superCommandOption.activate = self.superCommandOptionActivate.object
        self.superCommand.addOption(self.superCommandOption)

        self.program = Program("program", self.input.object, self.output.object)
        self.program.addCommand(self.superCommand)

    def tearDown(self):
        self.mocks.tearDown()

    def testExecute(self):
        self.subCommandExecute.expect()
        self.program._execute("foo", "bar")

    def testExecuteWithSuperCommandOption(self):
        self.superCommandOptionActivate.expect("bar").andReturn(["bar"])
        self.subCommandExecute.expect()
        self.program._execute("foo", "--super-command-option", "bar")

    def testExecuteWithSubCommandOption(self):
        self.subCommandOptionActivate.expect().andReturn([])
        self.subCommandExecute.expect()
        self.program._execute("foo", "bar", "--sub-command-option")

    def testDoc(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program command [options]
          Interactive mode:   program

        Commands:
          help  Display this help message
          foo   a super command
        """))
        self.program._execute("help")

    def testDocOfSuperCommand(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program foo [foo-options] sub-command [options]
          Interactive mode:   foo [foo-options] sub-command [options]

        Options of command 'foo':
          --super-command-option  A super-command option

        Sub-commands:
          bar  barbaz a frobnicator
        """))
        self.program._execute("help", "foo")

    def testDocOfSubCommand(self):
        self.output.expect.write(textwrap.dedent("""\
        Usage:
          Command-line mode:  program foo [foo-options] bar [bar-options]
          Interactive mode:   foo [foo-options] bar [bar-options]

        Options of command 'foo':
          --super-command-option  A super-command option

        Options of command 'bar':
          --sub-command-option  A sub-command option
        """))
        self.program._execute("help", "foo", "bar")