Actually execute the tests for the getter/setter/deleter tests on properties.

Also fix the test by having the test classes inherit from object.

Are the getter/setter/deleter attributes supposed to be able to chain?  As of
right now they can't as the property tries to call what the property returns,
which is another property when they are chained.
This commit is contained in:
Brett Cannon 2007-12-25 00:14:34 +00:00
parent a6ae8974c1
commit 4e438bcc56
1 changed files with 12 additions and 7 deletions

View File

@ -2131,7 +2131,7 @@ def properties():
def properties_plus(): def properties_plus():
class C: class C(object):
foo = property(doc="hello") foo = property(doc="hello")
@foo.getter @foo.getter
def foo(self): def foo(self):
@ -2146,8 +2146,11 @@ def properties_plus():
assert C.foo.__doc__ == "hello" assert C.foo.__doc__ == "hello"
assert not hasattr(c, "foo") assert not hasattr(c, "foo")
c.foo = -42 c.foo = -42
assert hasattr(c, '_foo')
assert c._foo == 42
assert c.foo == 42 assert c.foo == 42
del c.foo del c.foo
assert not hasattr(c, '_foo')
assert not hasattr(c, "foo") assert not hasattr(c, "foo")
class D(C): class D(C):
@ -2163,20 +2166,20 @@ def properties_plus():
del d.foo del d.foo
del d.foo del d.foo
class E: class E(object):
@property @property
def foo(self): def foo(self):
return self._foo return self._foo
@foo.setter @foo.setter
def foo (self, value): def foo(self, value):
raise RuntimeError raise RuntimeError
@foo.setter @foo.setter
def foo(self, value):
self._foo = abs(value)
@foo.deleter @foo.deleter
def foo(self, value=None): def foo(self, value=None):
if value is None: del self._foo
del self._foo
else:
self._foo = abs(value)
e = E() e = E()
e.foo = -42 e.foo = -42
assert e.foo == 42 assert e.foo == 42
@ -2193,6 +2196,7 @@ def properties_plus():
f.foo = -10 f.foo = -10
assert f.foo == 0 assert f.foo == 0
del f.foo del f.foo
print "*** HIT"
def supers(): def supers():
@ -4477,6 +4481,7 @@ def test_main():
recursions() recursions()
weakrefs() weakrefs()
properties() properties()
properties_plus()
supers() supers()
inherits() inherits()
keywords() keywords()