Add a test for the new getset type.

This commit is contained in:
Guido van Rossum 2001-08-24 15:24:24 +00:00
parent 271410ad18
commit 76f0cb85c2
1 changed files with 24 additions and 0 deletions

View File

@ -1069,6 +1069,29 @@ def weakrefs():
verify(r() is None) verify(r() is None)
del r del r
def getsets():
if verbose: print "Testing getset..."
class C(object):
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = getset(getx, setx, delx)
a = C()
verify(not hasattr(a, "x"))
a.x = 42
verify(a._C__x == 42)
verify(a.x == 42)
del a.x
verify(not hasattr(a, "x"))
verify(not hasattr(a, "_C__x"))
C.x.__set__(a, 100)
verify(C.x.__get__(a) == 100)
## C.x.__set__(a)
## verify(not hasattr(a, "x"))
def all(): def all():
lists() lists()
dicts() dicts()
@ -1098,6 +1121,7 @@ def all():
methods() methods()
specials() specials()
weakrefs() weakrefs()
getsets()
all() all()