test,verdict = "enable_wrap, disable_wrap, wrap_is_enabled",FAIL try: def succ(x): return x+1 def add2(*a,**kw): rv = yield aspects.proceed yield aspects.return_stop(rv+2) def add4(*a,**kw): rv = yield aspects.proceed yield aspects.return_stop(rv+4) a2=aspects.with_wrap(add2,succ) a4=aspects.with_wrap(add4,succ) wis=aspects.wrap_is_enabled if wis(succ,a2)!=1 or wis(succ,a4)!=1: raise Exception("wis1") aspects.disable_wrap(succ,a4) if wis(succ,a2)!=1 or wis(succ,a4)!=0: raise Exception("wis2") if succ(0)!=3: raise Exception("succ(0)==%s!=3" % succ(0)) aspects.disable_wrap(succ,a2) if wis(succ,a2)!=0 or wis(succ,a4)!=0: raise Exception("wis3") if succ(0)!=1: raise Exception("succ(0)==%s!=1" % succ(0)) aspects.enable_wrap(succ,a4) if wis(succ,a2)!=0 or wis(succ,a4)!=1: raise Exception("wis4") if succ(0)!=5: raise Exception("succ(0)==%s!=5" % succ(0)) aspects.enable_wrap(succ,a2) if wis(succ,a2)!=1 or wis(succ,a4)!=1: raise Exception("wis5") if succ(0)!=7: raise Exception("succ(0)==%s!=7" % succ(0)) verdict=PASS finally: print verdict,test test,verdict = "instance-specific aspects",FAIL
test,verdict="keyword arguments, two different wraps on one method",FAIL try: surface_wrapnum=aspects.wrap_around(C.bar1,adv2) # bar1 is has now wraps adv2/adv1, it calls _foo0 which has wrap adv1 if o.bar1(num=8)==612: verdict=PASS finally: print verdict,test test,verdict="using wrap_count when two wraps",FAIL try: if aspects.wrap_count(C.bar1)==2: verdict=PASS else: print aspects.wrap_count(C.bar1) finally: print verdict,test test,verdict="disabling the deeper wrap",FAIL try: aspects.disable_wrap(C.bar1,0) # adv1 disabled if o.bar1(num=8)==512: verdict=PASS finally: print verdict,test test,verdict="testing wrap_is_enabled",FAIL try: if aspects.wrap_is_enabled(C.bar1,0)==0 and \ aspects.wrap_is_enabled(C.bar1,surface_wrapnum)==1: verdict=PASS finally: print verdict,test test,verdict="disabling the shallower wrap",FAIL try: aspects.disable_wrap(C.bar1,surface_wrapnum) # adv2 disabled if o.bar1(8)==112: verdict=PASS finally: print verdict,test
def succ(x): return x + 1 def add2(*a, **kw): rv = yield aspects.proceed yield aspects.return_stop(rv + 2) def add4(*a, **kw): rv = yield aspects.proceed yield aspects.return_stop(rv + 4) a2 = aspects.with_wrap(add2, succ) a4 = aspects.with_wrap(add4, succ) wis = aspects.wrap_is_enabled if wis(succ, a2) != 1 or wis(succ, a4) != 1: raise Exception("wis1") aspects.disable_wrap(succ, a4) if wis(succ, a2) != 1 or wis(succ, a4) != 0: raise Exception("wis2") if succ(0) != 3: raise Exception("succ(0)==%s!=3" % succ(0)) aspects.disable_wrap(succ, a2) if wis(succ, a2) != 0 or wis(succ, a4) != 0: raise Exception("wis3") if succ(0) != 1: raise Exception("succ(0)==%s!=1" % succ(0)) aspects.enable_wrap(succ, a4) if wis(succ, a2) != 0 or wis(succ, a4) != 1: raise Exception("wis4") if succ(0) != 5: raise Exception("succ(0)==%s!=5" % succ(0)) aspects.enable_wrap(succ, a2) if wis(succ, a2) != 1 or wis(succ, a4) != 1: raise Exception("wis5") if succ(0) != 7: raise Exception("succ(0)==%s!=7" % succ(0)) verdict = PASS finally: print verdict, test
surface_wrapnum = aspects.wrap_around(C.bar1, adv2) # bar1 is has now wraps adv2/adv1, it calls _foo0 which has wrap adv1 if o.bar1(num=8) == 612: verdict = PASS finally: print verdict, test test, verdict = "using wrap_count when two wraps", FAIL try: if aspects.wrap_count(C.bar1) == 2: verdict = PASS else: print aspects.wrap_count(C.bar1) finally: print verdict, test test, verdict = "disabling the deeper wrap", FAIL try: aspects.disable_wrap(C.bar1, 0) # adv1 disabled if o.bar1(num=8) == 512: verdict = PASS finally: print verdict, test test, verdict = "testing wrap_is_enabled", FAIL try: if aspects.wrap_is_enabled(C.bar1,0)==0 and \ aspects.wrap_is_enabled(C.bar1,surface_wrapnum)==1: verdict = PASS finally: print verdict, test test, verdict = "disabling the shallower wrap", FAIL try: aspects.disable_wrap(C.bar1, surface_wrapnum) # adv2 disabled