def test_runCmd_error(self): """ If there's any other kind of error """ s = ShellProtocol() s.showPrompt = lambda: None called = [] s.sendLine = called.append def fake(arg1): raise Exception('foo') s.cmd_foo = fake r = s.runCmd(*['foo', 'arg1']) self.assertEqual(r, False) self.assertEqual(len(called), 1)
def test_runCmd_badArgs(self): """ If the user supplies bad arguments """ s = ShellProtocol() s.showPrompt = lambda: None called = [] s.sendLine = called.append def fake(arg1, arg2): pass s.cmd_foo = fake r = s.runCmd(*['foo', 'arg1']) self.assertEqual(r, False) self.assertEqual(len(called), 1)
def test_runCmd(self): """ runCmd should find the command from arg[0] and run it with args[1:]* """ s = ShellProtocol() s.showPrompt = lambda: None called = [] def fake(*args): called.append(args) return 'hey' s.cmd_foo = fake r = s.runCmd(*['foo', 'arg1', 'arg2', 'arg3']) self.assertEqual(r, 'hey') self.assertEqual(len(called), 1) self.assertEqual(called[0], ('arg1', 'arg2', 'arg3'))