def testSpyOnOverriddenBaseClassMethod(self): SpySubClass = Spyable(methods=[NewBaseClass.eatCorn, "mymethod"])( SubClassWithOverride) z = SpySubClass('a', 'b') z.mymethod("hi") z.eatCorn("canned") self.assertEquals(z.spylog.getLast('eatCorn'), None) self.assertEquals(z.spylog.getLast('mymethod')[pr], ({'inp': 'hi'}, None))
def testSpyOnCertainClass(self): # known limitation... when super() is called, we are not spy-wrapping # base base class methods. SpySubClass = Spyable(methods=[NewBaseClass.eatCorn, "mymethod"])( SubClassWithOverrideAndSuperCall) z = SpySubClass('a', 'b') z.mymethod("hi") z.eatCorn("canned") self.assertEquals(z.spylog.getLast('eatCorn'), None) self.assertEquals(z.spylog.getLast('mymethod')[pr], ({'inp': 'hi'}, None))
def go(methods, ec: "expected counts"): SpySubClass = Spyable(methods=methods)(SubClass) z = SpySubClass('a', 'b') self.assertEquals(len(z.spylog), ec[0], "expected certain number of entries in the spy log") z.eatCorn('canned') z.eatCorn('whirled') self.assertEquals(len(z.spylog), ec[1], "expected certain number of entries in the spy log") z.eatCorn('creamed') z.mymethod("hello again") self.assertEquals(len(z.spylog), ec[2], "expected certain number of entries in the spy log")
def testEveryObjectGetsItsOwnSpyLog(self): SpySubClass = Spyable()(SubClass) y = SpySubClass('a', 'b') z = SpySubClass('x', 'y') self.checkOneInit(y, {'s': 'a', 'p': 'b'}) self.checkOneInit(z, {'s': 'x', 'p': 'y'})
def testSpyableSubClassWithOverride(self): SpySubClassOvrd = Spyable()(SubClassWithOverride) z = SpySubClassOvrd('x', 'y') self.runThroughAssertions(z, 'hooray!')
def testSpyableSubClass(self): SpySubClass = Spyable()(SubClass) z = SpySubClass('x', 'y') self.runThroughAssertions(z)
def testSpyableBaseClass(self): SpyBaseClass = Spyable()(NewBaseClass) z = SpyBaseClass('x', 'y') self.runThroughAssertions(z)
def testNew(self): X = Spyable(Node) print(X)