[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.14,1.15
Guido van Rossum
gvanrossum@users.sourceforge.net
Fri, 17 Aug 2001 04:43:19 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv30834
Modified Files:
test_descr.py
Log Message:
metaclass(): add tests for metaclasses written in Python: one that
subclasses type, one that doesn't (the latter isn't fully functional
yet).
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_descr.py 2001/08/16 20:41:56 1.14
--- test_descr.py 2001/08/17 11:43:17 1.15
***************
*** 382,385 ****
--- 382,418 ----
def myself(cls): return cls
verify(D.myself() == D)
+ d = D()
+ verify(d.__class__ is D)
+ class M1(type):
+ def __new__(cls, name, bases, dict):
+ dict['__spam__'] = 1
+ return type.__new__(cls, name, bases, dict)
+ class C:
+ __metaclass__ = M1
+ verify(C.__spam__ == 1)
+ c = C()
+ verify(c.__spam__ == 1)
+ class _instance(object):
+ pass
+ class M2(object):
+ def __new__(cls, name, bases, dict):
+ self = object.__new__(cls)
+ self.name = name
+ self.bases = bases
+ self.dict = dict
+ return self
+ __new__ = staticmethod(__new__)
+ def __call__(self):
+ it = _instance()
+ # XXX Should do more, but that doesn't work yet
+ return it
+ class C:
+ __metaclass__ = M2
+ def spam(self):
+ return 42
+ verify(C.name == 'C')
+ verify(C.bases == ())
+ verify('spam' in C.dict)
+ c = C()
def pymods():