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")
class OptionGrouping(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.mocks = MockMockMock.Engine() self.input = self.mocks.create("input") self.output = self.mocks.create("output") self.p = Program("program", self.input.object, self.output.object) self.option = Option("option", "An option in a group") def tearDown(self): unittest.TestCase.tearDown(self) self.mocks.tearDown() def testDoc(self): g = self.p.createOptionGroup("Option group") g.addOption(self.option) self.output.expect.write( textwrap.dedent("""\ Usage: Command-line mode: program [global-options] command [options] Interactive mode: program [global-options] Global options: Option group: --option An option in a group Commands: help Display this help message """)) self.p._execute("help") def testDocWithRecursiveGroups(self): g1 = self.p.createOptionGroup("Option group 1") g2 = g1.createOptionGroup("Option group 2") g3 = g2.createOptionGroup("Option group 3") g3.addOption(self.option) self.output.expect.write( textwrap.dedent("""\ Usage: Command-line mode: program [global-options] command [options] Interactive mode: program [global-options] Global options: Option group 1: Option group 2: Option group 3: --option An option in a group Commands: help Display this help message """)) self.p._execute("help")
def test(self): mocks = MockMockMock.Engine() input = mocks.create("input") output = mocks.create("output") p = Program("program", input.object, output.object, "Custom#") output.expect.write("Custom#") input.expect.readline().and_return("") p._execute()
def test(self): mocks = MockMockMock.Engine() input = mocks.create("input") output = mocks.create("output") p = Program("program", input.object, output.object, "Custom#") output.expect.write("Custom#") input.expect.readline().andReturn("") p._execute()
class OptionGrouping(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.mocks = MockMockMock.Engine() self.input = self.mocks.create("input") self.output = self.mocks.create("output") self.p = Program("program", self.input.object, self.output.object) self.option = Option("option", "An option in a group") def tearDown(self): unittest.TestCase.tearDown(self) self.mocks.tearDown() def testDoc(self): g = self.p.createOptionGroup("Option group") g.addOption(self.option) self.output.expect.write(textwrap.dedent("""\ Usage: Command-line mode: program [global-options] command [options] Interactive mode: program [global-options] Global options: Option group: --option An option in a group Commands: help Display this help message """)) self.p._execute("help") def testDocWithRecursiveGroups(self): g1 = self.p.createOptionGroup("Option group 1") g2 = g1.createOptionGroup("Option group 2") g3 = g2.createOptionGroup("Option group 3") g3.addOption(self.option) self.output.expect.write(textwrap.dedent("""\ Usage: Command-line mode: program [global-options] command [options] Interactive mode: program [global-options] Global options: Option group 1: Option group 2: Option group 3: --option An option in a group Commands: help Display this help message """)) self.p._execute("help")
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")
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")
class CommandGrouping(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.mocks = MockMockMock.Engine() self.input = self.mocks.create("input") self.output = self.mocks.create("output") self.p = Program("program", self.input.object, self.output.object) self.command = Command("command", "A command in a group") self.commandExecute = self.mocks.create("commandExecute") self.command.execute = self.commandExecute.object def tearDown(self): unittest.TestCase.tearDown(self) self.mocks.tearDown() def testDoc(self): g = self.p.createCommandGroup("Command group") g.addCommand(self.command) self.output.expect.write(textwrap.dedent("""\ Usage: Command-line mode: program command [options] Interactive mode: program Commands: help Display this help message Command group: command A command in a group """)) self.p._execute("help") def testExecute(self): g = self.p.createCommandGroup("Command group") g.addCommand(self.command) self.commandExecute.expect() self.p._execute("command") def testExecuteWithRecursiveGroups(self): g1 = self.p.createCommandGroup("Command group 1") g2 = g1.createCommandGroup("Command group 2") g3 = g2.createCommandGroup("Command group 3") g3.addCommand(self.command) self.commandExecute.expect() self.p._execute("command") def testDocWithRecursiveGroups(self): g1 = self.p.createCommandGroup("Command group 1") g2 = g1.createCommandGroup("Command group 2") g3 = g2.createCommandGroup("Command group 3") g3.addCommand(self.command) self.output.expect.write(textwrap.dedent("""\ Usage: Command-line mode: program command [options] Interactive mode: program Commands: help Display this help message Command group 1: Command group 2: Command group 3: command A command in a group """)) self.p._execute("help")
class CommandGrouping(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.mocks = MockMockMock.Engine() self.input = self.mocks.create("input") self.output = self.mocks.create("output") self.p = Program("program", self.input.object, self.output.object) self.command = Command("command", "A command in a group") self.commandExecute = self.mocks.create("commandExecute") self.command.execute = self.commandExecute.object def tearDown(self): unittest.TestCase.tearDown(self) self.mocks.tearDown() def testDoc(self): g = self.p.createCommandGroup("Command group") g.addCommand(self.command) self.output.expect.write( textwrap.dedent("""\ Usage: Command-line mode: program command [options] Interactive mode: program Commands: help Display this help message Command group: command A command in a group """)) self.p._execute("help") def testExecute(self): g = self.p.createCommandGroup("Command group") g.addCommand(self.command) self.commandExecute.expect() self.p._execute("command") def testExecuteWithRecursiveGroups(self): g1 = self.p.createCommandGroup("Command group 1") g2 = g1.createCommandGroup("Command group 2") g3 = g2.createCommandGroup("Command group 3") g3.addCommand(self.command) self.commandExecute.expect() self.p._execute("command") def testDocWithRecursiveGroups(self): g1 = self.p.createCommandGroup("Command group 1") g2 = g1.createCommandGroup("Command group 2") g3 = g2.createCommandGroup("Command group 3") g3.addCommand(self.command) self.output.expect.write( textwrap.dedent("""\ Usage: Command-line mode: program command [options] Interactive mode: program Commands: help Display this help message Command group 1: Command group 2: Command group 3: command A command in a group """)) self.p._execute("help")