-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added metaclass test from standard test suite, Fixed attribute lookup…
… in metaclass.
- Loading branch information
1 parent
67ea8a1
commit 0a88d96
Showing
5 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# test_metaclass fragment from standard Python test suite | ||
def test_metaclass(): | ||
# Testing metaclasses... | ||
class C(metaclass=type): | ||
def __init__(self): | ||
self.__state = 0 | ||
def getstate(self): | ||
return self.__state | ||
def setstate(self, state): | ||
self.__state = state | ||
a = C() | ||
___assertEqual(a.getstate(), 0) | ||
a.setstate(10) | ||
___assertEqual(a.getstate(), 10) | ||
class _metaclass(type): | ||
def myself(cls): return cls | ||
class D(metaclass=_metaclass): | ||
pass | ||
___assertEqual(D.myself(), D) | ||
d = D() | ||
___assertEqual(d.__class__, D) | ||
class M1(type): | ||
def __new__(cls, name, bases, dict): | ||
dict['__spam__'] = 1 | ||
return type.__new__(cls, name, bases, dict) | ||
class C(metaclass=M1): | ||
pass | ||
___assertEqual(C.__spam__, 1) | ||
c = C() | ||
___assertEqual(c.__spam__, 1) | ||
|
||
test_metaclass() |