def testProxyArgument(self): global mockFuncArg if pmi.isController: pmi.call(mockFunc, self.obj) else: pmi.call() self.assertEqual(mockFuncArg, self.pmiobj)
def testProperty(self): if pmi.isController: self.obj.x = 42 self.assertEqual(self.obj.x, 42) else: pmi.call() self.assertEqual(self.pmiobj.x, 42)
def testCallInherited(self): if pmi.isController: obj = MockProxyDerived() pmiobj = obj.pmiobject obj.g(42) else: pmiobj = pmi.create() pmi.call() self.assertEqual(pmiobj.gArg, 42)
def testFunction(self): global mockFuncCalled self.assertEqual(pmi.call(mockFunc), 42) self.assert_(mockFuncCalled) self.assertFalse("mockFunc2" in globals()) self.assertEqual(pmi.call("mockFunc2"), 52) self.assert_(pmi.mockFunc2Called) self.assertFalse("mockFunc2" in globals())
def testCallOverridden(self): if pmi.isController: obj = MockProxyDerived() pmiobj = obj.pmiobject obj.f(52) else: pmiobj = pmi.create() pmi.call() self.assert_(hasattr(pmiobj, "fDerivedCalled")) self.assert_(hasattr(pmiobj, "fCalled")) self.assertEqual(pmiobj.arg, 42) self.assertEqual(pmiobj.arg2, 52)
def testPMIClassArgument(self): global mockFuncArg, mockFuncArgs obj = pmi.create(MockClass) self.assert_(isinstance(obj, MockClass)) # pass the PMI class as argument and its id pmi.call(mockFunc, obj, id(obj)) # on all workers, obj should now be in the object self.assertEqual(mockFuncArg, obj) # but it should not have the same id on all workers! if pmi.isController: self.assertEqual(mockFuncArgs[0], id(obj)) else: self.assertNotEqual(mockFuncArgs[0], id(obj))
def testController(self): global mockFuncArg, mockFuncArgs, mockFuncKwds obj = pmi.call(mockFunc, arg=42, __pmictr_arg=52) if pmi.isController: self.assertEqual(mockFuncArg, 52) else: self.assertEqual(mockFuncArg, 42)
def testCallMethod(self): # call via instance obj = pmi.create(MockClass) self.assertEqual(pmi.call(obj.f), 42) self.assert_(obj.fCalled) # call via class obj2 = pmi.create(MockClass) self.assertFalse(obj2.fCalled) self.assertEqual(pmi.call(MockClass.f, obj2), 42) self.assert_(obj2.fCalled) # call via string obj3 = pmi.create("MockClass2") self.assertEqual(pmi.call("MockClass2.f", obj3), 52) # call via instance and method name obj4 = pmi.create(MockClass) self.assertEqual(pmi.call(obj4, "f"), 42) self.assert_(obj4.fCalled)
def mandelbrot(c1, c2, size, maxit): """Compute the mandelbrot set between c1 and c2 (both expected to be pairs of float values), using maximally maxit iterations per point.""" return pmi.call("mandelbrot_pmi.mandelbrot_parallel", c1, c2, size, maxit)
def testMixed(self): global mockFuncArg, mockFuncArgs, mockFuncKwds pmi.call(mockFunc, 42, 52, 62, arg1=72, arg2=82) self.assertEqual(mockFuncArg, 42) self.assertEqual(mockFuncArgs, (52, 62)) self.assertEqual(mockFuncKwds, {"arg1": 72, "arg2": 82})
def testKeywords(self): global mockFuncArg, mockFuncArgs, mockFuncKwds pmi.call(mockFunc, arg1=42, arg2=52) self.assertEqual(mockFuncArg, None) self.assertEqual(mockFuncArgs, ()) self.assertEqual(mockFuncKwds, {"arg1": 42, "arg2": 52})
def testList(self): global mockFuncArg, mockFuncArgs pmi.call(mockFunc, 42, 52, 62) self.assertEqual(mockFuncArg, 42) self.assertEqual(mockFuncArgs, (52, 62)) self.assertEqual(mockFuncKwds, {})
def testSimple(self): global mockFuncArg pmi.call(mockFunc, 42) self.assertEqual(mockFuncArg, 42) self.assertEqual(mockFuncArgs, ()) self.assertEqual(mockFuncKwds, {})
def f4(self): return pmi.call(self, "f4")
def testBuiltinFunction(self): self.assertEqual(pmi.call(zip), []) # by string self.assertEqual(pmi.call("zip"), [])
def testCall(self): if pmi.isController: self.assertEqual(self.obj.f2(), 52) else: self.assertEqual(pmi.call(), 52) self.assertEqual(self.pmiobj.called, "f2")
def testCallViaSelf(self): if pmi.isController: self.assertEqual(self.obj.f4(), 72) else: self.assertEqual(pmi.call(), 72) self.assertEqual(self.pmiobj.called, "f4")