def _test_completeFiles(self, tests): protocol = ShellProtocol(None, commandsClass=SomeCommands) commands = protocol.commands def c(word): # One token d = commands.complete_files((word, )) d.addCallback(lambda c: sorted(c)) return d def d(word): # Multiple tokens d = commands.complete_files(("XYZZY", word)) d.addCallback(lambda c: sorted(c)) return d def e(word): # No tokens d = commands.complete_files(()) d.addCallback(lambda c: sorted(c)) return d for word, completions in tests: if word is None: self.assertEquals((yield e(word)), completions, "Completing %r" % (word, )) else: self.assertEquals((yield c(word)), completions, "Completing %r" % (word, )) self.assertEquals((yield d(word)), completions, "Completing %r" % (word, ))
def test_completeCommands(self): protocol = ShellProtocol(None, commandsClass=SomeCommands) commands = protocol.commands def c(word): return sorted(commands.complete_commands(word)) self.assertEquals(c(""), ["a", "b"]) self.assertEquals(c("a"), [""]) self.assertEquals(c("h"), ["idden"]) self.assertEquals(c("f"), [])
def test_commandsSome(self): protocol = ShellProtocol(None, commandsClass=SomeCommands) commands = protocol.commands allCommands = commands.commands() self.assertEquals(sorted(allCommands), [ ("a", commands.cmd_a), ("b", commands.cmd_b), ]) allCommands = commands.commands(showHidden=True) self.assertEquals(sorted(allCommands), [ ("a", commands.cmd_a), ("b", commands.cmd_b), ("hidden", commands.cmd_hidden), ])
def setUp(self): self.protocol = ShellProtocol(None, commandsClass=CommandsBase) self.commands = self.protocol.commands