def foo(self,x): return x+2 class newc(object): def foo(self,x): return x+3 def adv(*a): yield aspects.return_stop(42) def adv2(*a): yield aspects.return_stop(52) aspects.with_wrap(adv,foo,c.foo,newc.foo) o=c() newo=newc() if not (foo(0)==o.foo(1)==newo.foo(2)==42): raise Exception("first wrapping failed already") aspects.with_wrap(adv2,foo,c.foo,newc.foo) if not (foo(0)==o.foo(1)==newo.foo(2)==52): raise Exception("second wrapping failed already") w1=aspects.peel_around(foo) w2=aspects.peel_around(c.foo) w3=aspects.peel_around(newc.foo) if not (foo(0)==o.foo(1)==newo.foo(2)==42): raise Exception("first peeling failed") aspects.peel_around(foo) aspects.peel_around(c.foo) aspects.peel_around(newc.foo) if not (foo(0)==1 and o.foo(0)==2 and newo.foo(0)==3): raise Exception("second peeling failed") aspects.with_wrap(w1,foo) aspects.with_wrap(w2,c.foo) aspects.with_wrap(w3,newc.foo) if not (foo(0)==o.foo(1)==newo.foo(2)==52): raise Exception("peels could not be put back") verdict=PASS
test,verdict="wrap_around a private method (called by a public method)",FAIL try: aspects.wrap_around(C._C__foo0,adv1) if o.foo1(num=0)==501: verdict=PASS finally: print verdict,test test,verdict="using wrap_count on private method",FAIL try: if aspects.wrap_count(C._C__foo0)==1: verdict=PASS finally: print verdict,test test,verdict="peel_around clear advices",FAIL try: try: aspects.peel_around(C.foo1) aspects.peel_around(C._C__foo0) if o.foo1(num=0)==1: verdict=PASS except: pass finally: print verdict,test test,verdict="using wrap_count on peeled methods",FAIL try: if aspects.wrap_count(C.foo1)==0 and \ aspects.wrap_count(C._C__foo0)==0: verdict=PASS finally: print verdict,test test,verdict="wrap_around_re, wrap_around, normal arguments",FAIL try: aspects.wrap_around_re(C,'foo[0-9]',adv1) if o.foo1(0)==101 and o.foo2(0)==102: verdict=PASS
def adv(*a): yield aspects.return_stop(42) def adv2(*a): yield aspects.return_stop(52) aspects.with_wrap(adv, foo, c.foo, newc.foo) o = c() newo = newc() if not (foo(0) == o.foo(1) == newo.foo(2) == 42): raise Exception("first wrapping failed already") aspects.with_wrap(adv2, foo, c.foo, newc.foo) if not (foo(0) == o.foo(1) == newo.foo(2) == 52): raise Exception("second wrapping failed already") w1 = aspects.peel_around(foo) w2 = aspects.peel_around(c.foo) w3 = aspects.peel_around(newc.foo) if not (foo(0) == o.foo(1) == newo.foo(2) == 42): raise Exception("first peeling failed") aspects.peel_around(foo) aspects.peel_around(c.foo) aspects.peel_around(newc.foo) if not (foo(0) == 1 and o.foo(0) == 2 and newo.foo(0) == 3): raise Exception("second peeling failed") aspects.with_wrap(w1, foo) aspects.with_wrap(w2, c.foo) aspects.with_wrap(w3, newc.foo) if not (foo(0) == o.foo(1) == newo.foo(2) == 52): raise Exception("peels could not be put back") verdict = PASS
try: aspects.wrap_around(C._C__foo0, adv1) if o.foo1(num=0) == 501: verdict = PASS finally: print verdict, test test, verdict = "using wrap_count on private method", FAIL try: if aspects.wrap_count(C._C__foo0) == 1: verdict = PASS finally: print verdict, test test, verdict = "peel_around clear advices", FAIL try: try: aspects.peel_around(C.foo1) aspects.peel_around(C._C__foo0) if o.foo1(num=0) == 1: verdict = PASS except: pass finally: print verdict, test test, verdict = "using wrap_count on peeled methods", FAIL try: if aspects.wrap_count(C.foo1)==0 and \ aspects.wrap_count(C._C__foo0)==0: verdict = PASS finally: print verdict, test