def test_getCommands_cache(self): """ getCommands should cache the results """ s = ShellProtocol() c = s.getCommands() def f(): pass s.cmd_something = f c2 = s.getCommands() self.assertEqual(c, c2)
def test_help(self): """ Help should spit out the first line of all doc strings of all commands """ class Fake: def __init__(self, doc): self.__doc__ = doc s = ShellProtocol() foo = Fake(''' this is something here. and not here ''') bar = Fake(''' bar is this guy''') s.getCommands = lambda: {'foo': foo, 'bar': bar} called = [] s.sendLine = called.append s.cmd_help() r = '\n'.join(called) self.assertTrue('this is something here.' in r) self.assertTrue('and not here' not in r, 'Only the first line should be included') self.assertTrue('bar is this guy' in r)
def test_getCommands(self): """ Should return a dictionary where the key is the command name and the value is the function called to run the command. """ s = ShellProtocol() def f(): pass s.cmd_something = f c = s.getCommands() self.assertEqual(c['something'], f)