Beispiel #1
0
 def testCflowNesting(self):
     Foo = self.Foo
     advice = self.Advice()
     f = Foo()
     pc = CFlow(Call(Foo.bar))
     around(pc, advice.notify)
     f.bar()
     self.assertEqual(len(advice.events), 3)
Beispiel #2
0
 def testRecursive(self):
     Foo = self.Foo
     f = Foo()
     pc = Call(Foo.recursive) & ~CFlowBelow(Call(Foo.recursive))
     advice = self.Advice()
     around(pc, advice.notify)
     self.assertEqual(f.recursive(5), 120)
     self.assertEqual(len(advice.events), 1)
Beispiel #3
0
 def testCFlow(self):
     Foo = self.Foo
     advice = self.Advice()
     f = Foo()
     bazInBoo = Call(Foo.baz) & CFlow(Call(Foo.bar))
     around(bazInBoo, advice.notify)
     f.baz()
     self.assertEqual(len(advice.events), 0)
     f.bar()
     self.assertEqual(len(advice.events), 1)
Beispiel #4
0
 def testCflow(self):
     class Foo:
         __metaclass__ = Advisable
         def foo(self):
             self.bar()
         def bar(self):
             pass
     a = self.Advice()
     f = Foo()
     pc = CFlow(Call(Foo.foo))
     around(pc, a.notify)
     f.foo()
     self.assertEqual(len(a.events), 2)
Beispiel #5
0
 def testSubclass(self):
     class Foo:
         __metaclass__ = Advisable
         def foo(self):
             pass            
     class Bar(Foo):
         def foo(self):
             pass
     b = Bar()
     a = self.Advice()
     pc = Call(Foo.foo)
     around(pc, a.notify)
     b.foo()
     self.assertEqual(len(a.events), 1)
Beispiel #6
0
 def testTwoClasses(self):
     class Foo:
         __metaclass__ = Advisable
         def foo(self, b):
             b.bar()
     class Bar:
         __metaclass__ = Advisable
         def bar(self):
             pass
     pc = Call(Bar.bar) & CFlow(Call(Foo.foo))
     a = self.Advice()
     around(pc, a.notify)
     f = Foo()
     b = Bar()
     f.foo(b)
     self.assertEqual(len(a.events), 1)
     self.assertEqual(a.events[0].getMethod().__name__, 'bar')
Beispiel #7
0
    def testOrPc(self):
        class Foo:
            __metaclass__ = Advisable
            def foo(self):
                self.bar()
            def bar(self):
                self.baz()
            def baz(self):
                pass

        pc = CFlow(Call(Foo.bar) & CFlow(Call(Foo.foo)))
        f = Foo()
        a = self.Advice()
        around(pc, a.notify)
        f.bar()
        f.baz()
        self.assertEqual(len(a.events), 0)
        f.foo()
        self.assertEqual(len(a.events), 2)
        self.assertEqual(a.events[0].getMethod().__name__, 'bar')
        self.assertEqual(a.events[1].getMethod().__name__, 'baz')
Beispiel #8
0
        print 'calling %s %d' %(event.getMethod(), self.call)
        r = event.callNextFunction(event.getArg('n'))
        print 'after %s %d' %(event.getMethod(), self.call)
        self.call -= 1
        return r

    def hey(self, event):
        print 'hey'
        
if __name__ == '__main__':
    from aspect import Call, around

    def p(s):
        print s
        
    ca = CacheAdvice()
    f = Fib()
    #import pdb
    
    print 'without:'

    f.fibonacci(10)
    around(Call(Fib.fibonacci), ca.advice)
    
    #around(Call(Fib.fibonacci), ca.trace)
    
    #around(Call(Fib.fibonacci), ca.advice)

    print 'with:'
#    f.fibonacci(10)