Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e747add

Browse files
committed
Python: Descriptor tests fixup (3/3)
Better tests for properties
1 parent aed7bfb commit e747add

3 files changed

Lines changed: 62 additions & 14 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| 13 | classmethod() | 14 | Function c1 |
2-
| 20 | classmethod() | 17 | Function c2 |
3-
| 21 | classmethod() | 17 | Function c2 |
4-
| 23 | staticmethod() | 24 | Function s1 |
5-
| 30 | staticmethod() | 27 | Function s2 |
6-
| 31 | staticmethod() | 27 | Function s2 |
1+
| 55 | classmethod() | 56 | Function c1 |
2+
| 62 | classmethod() | 59 | Function c2 |
3+
| 63 | classmethod() | 59 | Function c2 |
4+
| 65 | staticmethod() | 66 | Function s1 |
5+
| 72 | staticmethod() | 69 | Function s2 |
6+
| 73 | staticmethod() | 69 | Function s2 |
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
| test.py:4:5:4:16 | Function f | getter | test.py:3:6:3:13 | Property f |
2-
| test.py:8:5:8:23 | Function f | setter | test.py:3:6:3:13 | Property f |
1+
| test.py:6:5:6:16 | Function x | getter | test.py:5:6:5:13 | Property x |
2+
| test.py:11:5:11:23 | Function x | setter | test.py:5:6:5:13 | Property x |
3+
| test.py:15:5:15:16 | Function x | deleter | test.py:5:6:5:13 | Property x |
4+
| test.py:21:5:21:16 | Function x | getter | test.py:20:6:20:13 | Property x |
5+
| test.py:28:5:28:19 | Function getx | getter | test.py:37:9:37:59 | Property getx |
6+
| test.py:31:5:31:26 | Function setx | setter | test.py:37:9:37:59 | Property getx |
7+
| test.py:34:5:34:19 | Function delx | deleter | test.py:37:9:37:59 | Property getx |
8+
| test.py:41:5:41:19 | Function getx | getter | test.py:44:9:44:22 | Property getx |

python/ql/test/library-tests/descriptors/test.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
class C(object):
1+
class WithDecorator(object):
2+
def __init__(self):
3+
self._x = None
24

35
@property
4-
def f(self):
5-
return self._f
6+
def x(self):
7+
"""I'm the 'x' property."""
8+
return self._x
69

7-
@f.setter
8-
def f(self, value):
9-
self._f = value
10+
@x.setter
11+
def x(self, value):
12+
self._x = value
13+
14+
@x.deleter
15+
def x(self):
16+
del self._x
17+
18+
class WithDecoratorOnlyGetter(object):
19+
20+
@property
21+
def x(self):
22+
return 42
23+
24+
class WithoutDecorator(object):
25+
def __init__(self):
26+
self._x = None
27+
28+
def getx(self):
29+
return self._x
30+
31+
def setx(self, value):
32+
self._x = value
33+
34+
def delx(self):
35+
del self._x
36+
37+
x = property(getx, setx, delx, "I'm the 'x' property.")
38+
39+
class WithoutDecoratorOnlyGetter(object):
40+
41+
def getx(self):
42+
return 42
43+
44+
x = property(getx)
45+
46+
class WithoutDecoratorOnlySetter(object):
47+
48+
def setx(self, value):
49+
self._x = value
50+
51+
x = property(fset=setx) # TODO: Not handled
1052

1153
class D(object):
1254

0 commit comments

Comments
 (0)