Python: Descriptor tests fixup (3/3)

Better tests for properties
This commit is contained in:
Rasmus Wriedt Larsen
2020-02-12 16:32:50 +01:00
parent aed7bfb820
commit e747add485
3 changed files with 62 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
| 13 | classmethod() | 14 | Function c1 |
| 20 | classmethod() | 17 | Function c2 |
| 21 | classmethod() | 17 | Function c2 |
| 23 | staticmethod() | 24 | Function s1 |
| 30 | staticmethod() | 27 | Function s2 |
| 31 | staticmethod() | 27 | Function s2 |
| 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 |

View File

@@ -1,2 +1,8 @@
| test.py:4:5:4:16 | Function f | getter | test.py:3:6:3:13 | Property f |
| test.py:8:5:8:23 | Function f | setter | test.py:3:6:3:13 | Property f |
| test.py:6:5:6:16 | Function x | getter | test.py:5:6:5:13 | Property x |
| test.py:11:5:11:23 | Function x | setter | test.py:5:6:5:13 | Property x |
| test.py:15:5:15:16 | Function x | deleter | test.py:5:6:5:13 | Property x |
| test.py:21:5:21:16 | Function x | getter | test.py:20:6:20:13 | Property x |
| test.py:28:5:28:19 | Function getx | getter | test.py:37:9:37:59 | Property getx |
| test.py:31:5:31:26 | Function setx | setter | test.py:37:9:37:59 | Property getx |
| test.py:34:5:34:19 | Function delx | deleter | test.py:37:9:37:59 | Property getx |
| test.py:41:5:41:19 | Function getx | getter | test.py:44:9:44:22 | Property getx |

View File

@@ -1,12 +1,54 @@
class C(object):
class WithDecorator(object):
def __init__(self):
self._x = None
@property
def f(self):
return self._f
def x(self):
"""I'm the 'x' property."""
return self._x
@f.setter
def f(self, value):
self._f = value
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
class WithDecoratorOnlyGetter(object):
@property
def x(self):
return 42
class WithoutDecorator(object):
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
x = property(getx, setx, delx, "I'm the 'x' property.")
class WithoutDecoratorOnlyGetter(object):
def getx(self):
return 42
x = property(getx)
class WithoutDecoratorOnlySetter(object):
def setx(self, value):
self._x = value
x = property(fset=setx) # TODO: Not handled
class D(object):