

def testSubHook(self):
    'test interactions between base-class hooks and subclass hooks\n        '
    sub = SubClass()
    self.assertEquals(sub.calledSub, 0)
    self.assertEquals(sub.calledBase, 0)
    sub.func(1, b=2)
    self.assertEquals(sub.calledSub, 1)
    self.assertEquals(sub.calledBase, 1)
    hook.addPre(SubClass, 'func', subPre)
    self.assertEquals(sub.calledSub, 1)
    self.assertEquals(sub.calledBase, 1)
    self.assertEquals(sub.calledSubPre, 0)
    self.assertEquals(sub.calledBasePre, 0)
    sub.func(1, b=2)
    self.assertEquals(sub.calledSub, 2)
    self.assertEquals(sub.calledBase, 2)
    self.assertEquals(sub.calledSubPre, 1)
    self.assertEquals(sub.calledBasePre, 0)
    hook.addPre(BaseClass, 'func', basePre)
    BaseClass.func(sub, 1, b=2)
    self.assertEquals(sub.calledBase, 3)
    self.assertEquals(sub.calledBasePre, 1, str(sub.calledBasePre))
    sub.func(1, b=2)
    self.assertEquals(sub.calledBasePre, 2)
    self.assertEquals(sub.calledBase, 4)
    self.assertEquals(sub.calledSubPre, 2)
    self.assertEquals(sub.calledSub, 3)

dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/test/test_hook.py HookTestCase.testSubHook/original