diff options
author | Guido van Rossum <guido@python.org> | 2001-08-17 11:43:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-17 11:43:17 (GMT) |
commit | 309b56670491bd6e3b9ac8ba9aa0a5eef3d67446 (patch) | |
tree | 096030a9ffef6bb5f5559a09213195873f62b67f /Lib | |
parent | 8d32c8b59f9b5f4315f42a48b73a52adea3e10a2 (diff) | |
download | cpython-309b56670491bd6e3b9ac8ba9aa0a5eef3d67446.zip cpython-309b56670491bd6e3b9ac8ba9aa0a5eef3d67446.tar.gz cpython-309b56670491bd6e3b9ac8ba9aa0a5eef3d67446.tar.bz2 |
metaclass(): add tests for metaclasses written in Python: one that
subclasses type, one that doesn't (the latter isn't fully functional
yet).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_descr.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index f524dba..247a4c4 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -381,6 +381,39 @@ def metaclass(): class __metaclass__(type): 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(): if verbose: print "Testing Python subclass of module..." |