from unittest import TestCase, makeSuite, TestSuite |
from unittest import TestCase, makeSuite, TestSuite |
from peak.util.decorators import * |
from peak.util.decorators import * |
|
from peak.util.decorators import with_metaclass |
import sys |
import sys |
|
|
def ping(log, value): |
def ping(log, value): |
|
|
|
|
|
|
|
|
class DecoratorTests(TestCase): |
class DecoratorTests(TestCase): |
|
|
def testAssignAdvice(self): |
def testAssignAdvice(self): |
|
|
def testClassExec(self): |
def testClassExec(self): |
d = {'sys':sys, 'frameinfo':frameinfo} |
d = {'sys':sys, 'frameinfo':frameinfo} |
exec "class Foo: info=frameinfo(sys._getframe())" in d |
exec("class Foo: info=frameinfo(sys._getframe())", d) |
kind,module,f_locals,f_globals = d['Foo'].info |
kind,module,f_locals,f_globals = d['Foo'].info |
assert kind=="class", kind |
assert kind=="class", kind |
|
|
|
|
class M(type): pass |
class M(type): pass |
|
|
class C(M): |
class C(with_metaclass(M, M)): |
__metaclass__ = M |
|
ping([],1) |
ping([],1) |
|
|
C, = C |
C, = C |
class M1(type): pass |
class M1(type): pass |
class M2(type): pass |
class M2(type): pass |
|
|
class B1: __metaclass__ = M1 |
class B1(with_metaclass(M1)): pass |
class B2: __metaclass__ = M2 |
class B2(with_metaclass(M2)): pass |
|
|
try: |
try: |
class C(B1,B2): |
class C(B1,B2): |
|
|
class M3(M1,M2): pass |
class M3(M1,M2): pass |
|
|
class C(B1,B2): |
class C(with_metaclass(M3,B1,B2)): |
__metaclass__ = M3 |
|
ping([],1) |
ping([],1) |
|
|
assert isinstance(C,list) |
assert isinstance(C,list) |
|
|
|
|
|
|
|
|
|
|
def testMetaOfClass(self): |
def testMetaOfClass(self): |
|
|
class metameta(type): |
class metameta(type): |
pass |
pass |
|
|
class meta(type): |
class meta(with_metaclass(metameta, type)): |
__metaclass__ = metameta |
pass |
|
|
assert metaclass_for_bases((meta,type))==metameta |
assert metaclass_for_bases((meta,type))==metameta |
|
|
|
|
|
|
class ClassyMetaTests(TestCase): |
class ClassyMetaTests(TestCase): |
"""Test subclass/instance checking of classy for Python 2.6+ ABC mixin""" |
"""Test subclass/instance checking of classy for Python 2.6+ ABC mixin""" |
|
|
|
# avert 3.2 warnings, but still work on 2.3(!) |
|
failUnless = getattr(TestCase, 'assertTrue', TestCase.failUnless) |
|
failIf = getattr(TestCase, 'assertFalse', TestCase.failIf) |
|
|
def setUp(self): |
def setUp(self): |
class x(classy): pass |
class x(classy): pass |
class y(x): pass |
class y(x): pass |
|
|
|
|
|
|
|
|
|
|
|
|