def testGetResult(self): shell = Interpreter() result1 = shell.execute('a=10') result1['id'] = 0 result2 = shell.execute('b=20') result2['id'] = 0 execute= self.multiengine.execute get_result = self.multiengine.get_result self.addEngine(1) d = execute('a=10') d.addCallback(lambda _: get_result()) d.addCallback(lambda r: self.assertEquals(r[0], result1)) d.addCallback(lambda _: execute('b=20')) d.addCallback(lambda _: get_result(1)) d.addCallback(lambda r: self.assertEquals(r[0], result1)) d.addCallback(lambda _: get_result(2, block=False)) d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) d.addCallback(lambda r: self.assertEquals(r[0], result2)) return d
class EngineExecuteTestGenerator(TestGenerator): """A class for testing execute on the Engine.""" def __init__(self, inputs, testCaseInstance): self.shell = Interpreter() outputs = [self.shell.execute(c) for c in inputs] TestGenerator.__init__(self, inputs, outputs, testCaseInstance) def compare(self, actual, computed): actual['id'] = computed['id'] return self.testCaseInstance.assert_(actual == computed) def computeOutput(self, i): return self.testCaseInstance.engine.execute(i)
class MultiEngineExecuteAllTestGenerator(TestGenerator): """A class for testing execute on the Engine.""" def __init__(self, inputs, testCaseInstance, targets='all'): self.targets = targets self.shell = Interpreter() outputs = [self.shell.execute(c) for c in inputs] TestGenerator.__init__(self, inputs, outputs, testCaseInstance) def compare(self, actual, computed): for c in computed: actual['id'] = c['id'] self.testCaseInstance.assertEquals(actual, c) def computeOutput(self, i): return self.testCaseInstance.multiengine.execute(self.targets, i)
class EngineGetResultTestGenerator(TestGenerator): """A class for testing execute on the Engine.""" def __init__(self, inputs, testCaseInstance): self.shell = Interpreter() outputs = [self.shell.execute(c) for c in inputs] TestGenerator.__init__(self, inputs, outputs, testCaseInstance) def compare(self, actual, computed): actual['id'] = computed['id'] return self.testCaseInstance.assertEquals(actual, computed) def computeOutput(self, i): d = self.testCaseInstance.engine.execute(i) d.addCallback( lambda r: self.testCaseInstance.engine.get_result(r['number'])) return d