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()
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")