def testAddAttributeDynamically(self): class C: pass buf = StringIO() spyc = SpyProxy(C(), buf ) spyc.foo = 42 self.assertEqual(spyc.foo, 42) log = buf.getvalue() self.assertIn("attribute 'foo' written with value:42", log) self.assertIn("reading attribute 'foo' of type <type 'int'> with value 42", log)
def testClassMethod(self): class C: def __init__(self): self.toto = "3" def foo(self, arg1, arg2): return "in foo: arg1=",arg1," arg2=", arg2 buf = StringIO() c = C() spyC = SpyProxy(c, buf, "spyC") self.assertEqual(c.foo(1,2), spyC.foo(1,2))