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
try:
    class c:
        def foo(self): return 'foo'
        def bar(self): return 'bar'
    def adv1(self):
        yield aspects.return_stop('adv1')
Exemplo n.º 2
0
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

test,verdict="enabling all wraps",FAIL
try:
    for i in range(aspects.wrap_count(C.bar1)):
        aspects.enable_wrap(C.bar1,i)
    if o.bar1(num=8)==612: verdict=PASS
finally: print verdict,test

test,verdict="enabling, disabling and testing non-existing wraps",FAIL
try:
    try: aspects.disable_wrap(C.bar1,42)
    except aspects.AspectsException:
        try: aspects.disable_wrap(C.bar1,-1)
        except aspects.AspectsException:
            try: aspects.wrap_is_enabled(C.bar1,55)
            except aspects.AspectsException:
                verdict=PASS
finally: print verdict,test

test,verdict="wrap methods of certain instances",FAIL
    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
try:

    class c:
        def foo(self):
            return 'foo'
Exemplo n.º 4
0
       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

test, verdict = "enabling all wraps", FAIL
try:
    for i in range(aspects.wrap_count(C.bar1)):
        aspects.enable_wrap(C.bar1, i)
    if o.bar1(num=8) == 612: verdict = PASS
finally:
    print verdict, test

test, verdict = "enabling, disabling and testing non-existing wraps", FAIL
try:
    try:
        aspects.disable_wrap(C.bar1, 42)
    except aspects.AspectsException:
        try:
            aspects.disable_wrap(C.bar1, -1)
        except aspects.AspectsException:
            try:
                aspects.wrap_is_enabled(C.bar1, 55)
            except aspects.AspectsException: