def testSubHook(self): """test interactions between base-class hooks and subclass hooks """ sub = SubClass() self.assertEqual(sub.calledSub, 0) self.assertEqual(sub.calledBase, 0) sub.func(1, b=2) self.assertEqual(sub.calledSub, 1) self.assertEqual(sub.calledBase, 1) hook.addPre(SubClass, 'func', subPre) self.assertEqual(sub.calledSub, 1) self.assertEqual(sub.calledBase, 1) self.assertEqual(sub.calledSubPre, 0) self.assertEqual(sub.calledBasePre, 0) sub.func(1, b=2) self.assertEqual(sub.calledSub, 2) self.assertEqual(sub.calledBase, 2) self.assertEqual(sub.calledSubPre, 1) self.assertEqual(sub.calledBasePre, 0) # let the pain begin hook.addPre(BaseClass, 'func', basePre) BaseClass.func(sub, 1, b=2) # sub.func(1, b=2) self.assertEqual(sub.calledBase, 3) self.assertEqual(sub.calledBasePre, 1, str(sub.calledBasePre)) sub.func(1, b=2) self.assertEqual(sub.calledBasePre, 2) self.assertEqual(sub.calledBase, 4) self.assertEqual(sub.calledSubPre, 2) self.assertEqual(sub.calledSub, 3)
def testSubHook(self): """test interactions between base-class hooks and subclass hooks """ sub = SubClass() assert sub.calledSub == 0 assert sub.calledBase == 0 sub.func(1, b=2) assert sub.calledSub == 1 assert sub.calledBase == 1 hook.addPre(SubClass, 'func', subPre) assert sub.calledSub == 1 assert sub.calledBase == 1 assert sub.calledSubPre == 0 assert sub.calledBasePre == 0 sub.func(1, b=2) assert sub.calledSub == 2 assert sub.calledBase == 2 assert sub.calledSubPre == 1 assert sub.calledBasePre == 0 # let the pain begin hook.addPre(BaseClass, 'func', basePre) BaseClass.func(sub, 1, b=2) # sub.func(1, b=2) assert sub.calledBase == 3 assert sub.calledBasePre == 1, str(sub.calledBasePre) sub.func(1, b=2) assert sub.calledBasePre == 2 assert sub.calledBase == 4 assert sub.calledSubPre == 2 assert sub.calledSub == 3
def testBaseHook(self): """make sure that the base class's hook is called reliably """ base = BaseClass() self.assertEqual(base.calledBase, 0) self.assertEqual(base.calledBasePre, 0) base.func(1, 2) self.assertEqual(base.calledBase, 1) self.assertEqual(base.calledBasePre, 0) hook.addPre(BaseClass, "func", basePre) base.func(1, b=2) self.assertEqual(base.calledBase, 2) self.assertEqual(base.calledBasePre, 1) hook.addPost(BaseClass, "func", basePost) base.func(1, b=2) self.assertEqual(base.calledBasePost, 1) self.assertEqual(base.calledBase, 3) self.assertEqual(base.calledBasePre, 2) hook.removePre(BaseClass, "func", basePre) hook.removePost(BaseClass, "func", basePost) base.func(1, b=2) self.assertEqual(base.calledBasePost, 1) self.assertEqual(base.calledBase, 4) self.assertEqual(base.calledBasePre, 2)
def testBaseHook(self): """make sure that the base class's hook is called reliably """ base = BaseClass() self.assertEqual(base.calledBase, 0) self.assertEqual(base.calledBasePre, 0) base.func(1,2) self.assertEqual(base.calledBase, 1) self.assertEqual(base.calledBasePre, 0) hook.addPre(BaseClass, "func", basePre) base.func(1, b=2) self.assertEqual(base.calledBase, 2) self.assertEqual(base.calledBasePre, 1) hook.addPost(BaseClass, "func", basePost) base.func(1, b=2) self.assertEqual(base.calledBasePost, 1) self.assertEqual(base.calledBase, 3) self.assertEqual(base.calledBasePre, 2) hook.removePre(BaseClass, "func", basePre) hook.removePost(BaseClass, "func", basePost) base.func(1, b=2) self.assertEqual(base.calledBasePost, 1) self.assertEqual(base.calledBase, 4) self.assertEqual(base.calledBasePre, 2)
def testBaseHook(self): """make sure that the base class's hook is called reliably """ base = BaseClass() assert base.calledBase == 0 assert base.calledBasePre == 0 base.func(1,2) assert base.calledBase == 1 assert base.calledBasePre == 0 hook.addPre(BaseClass, "func", basePre) base.func(1, b=2) assert base.calledBase == 2 assert base.calledBasePre == 1 hook.addPost(BaseClass, "func", basePost) base.func(1, b=2) assert base.calledBasePost == 1 assert base.calledBase == 3 assert base.calledBasePre == 2 hook.removePre(BaseClass, "func", basePre) hook.removePost(BaseClass, "func", basePost) base.func(1, b=2) assert base.calledBasePost == 1 assert base.calledBase == 4 assert base.calledBasePre == 2
def testBaseHook(self): """make sure that the base class's hook is called reliably """ base = BaseClass() assert base.calledBase == 0 assert base.calledBasePre == 0 base.func(1, 2) assert base.calledBase == 1 assert base.calledBasePre == 0 hook.addPre(BaseClass, "func", basePre) base.func(1, b=2) assert base.calledBase == 2 assert base.calledBasePre == 1 hook.addPost(BaseClass, "func", basePost) base.func(1, b=2) assert base.calledBasePost == 1 assert base.calledBase == 3 assert base.calledBasePre == 2 hook.removePre(BaseClass, "func", basePre) hook.removePost(BaseClass, "func", basePost) base.func(1, b=2) assert base.calledBasePost == 1 assert base.calledBase == 4 assert base.calledBasePre == 2