Python: Add some confusing (but valid) property tests

This commit is contained in:
Rasmus Wriedt Larsen
2020-02-13 13:34:22 +01:00
parent 67e9edb820
commit 79a4d7e9cc
2 changed files with 55 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
| 55 | classmethod() | 56 | Function c1 |
| 62 | classmethod() | 59 | Function c2 |
| 63 | classmethod() | 59 | Function c2 |
| 65 | staticmethod() | 66 | Function s1 |
| 72 | staticmethod() | 69 | Function s2 |
| 73 | staticmethod() | 69 | Function s2 |
| 104 | classmethod() | 105 | Function c1 |
| 111 | classmethod() | 108 | Function c2 |
| 112 | classmethod() | 108 | Function c2 |
| 114 | staticmethod() | 115 | Function s1 |
| 121 | staticmethod() | 118 | Function s2 |
| 122 | staticmethod() | 118 | Function s2 |

View File

@@ -43,6 +43,13 @@ class WithoutDecoratorOnlyGetter(object):
x = property(getx)
class WithoutDecoratorOnlyGetterKWArg(object):
def getx(self):
return 42
x = property(fget=getx)
class WithoutDecoratorOnlySetter(object):
def setx(self, value):
@@ -50,6 +57,48 @@ class WithoutDecoratorOnlySetter(object):
x = property(fset=setx) # TODO: Not handled
class WithDecoratorOnlySetter(object):
x = property()
@x.setter
def x(self, value):
print('{} setting value to {}'.format(self.__class__, value))
class FunkyButValid(object):
def delx(self):
print("deleting x")
x = property(fdel=delx)
@x.setter
def y(self, value):
print('setting value to {}'.format(value))
@y.getter
def z(self):
return 42
wat = FunkyButValid()
try:
wat.x
except AttributeError as e:
print("x can't be read")
del wat.x
try:
wat.y
except AttributeError as e:
print("y can't be read")
wat.y = 1234
del wat.y
print(wat.z)
wat.z = 10
del wat.z
class D(object):
@classmethod