Skip to content

Commit e2a48b6

Browse files
committed
tests: Add property test.
1 parent 777b0f3 commit e2a48b6

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/basics/property.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
class A:
2+
def __init__(self, x):
3+
self._x = x
4+
5+
@property
6+
def x(self):
7+
print("x get")
8+
return self._x
9+
10+
a = A(1)
11+
print(a.x)
12+
13+
try:
14+
a.x = 2
15+
except AttributeError:
16+
print("AttributeError")
17+
18+
class B:
19+
def __init__(self, x):
20+
self._x = x
21+
22+
def xget(self):
23+
print("x get")
24+
return self._x
25+
26+
def xset(self, value):
27+
print("x set")
28+
self._x = value
29+
30+
x = property(xget, xset)
31+
32+
b = B(3)
33+
print(b.x)
34+
b.x = 4
35+
print(b.x)
36+
37+
class C:
38+
def __init__(self, x):
39+
self._x = x
40+
41+
@property
42+
def x(self):
43+
print("x get")
44+
return self._x
45+
46+
@x.setter
47+
def x(self, value):
48+
print("x set")
49+
self._x = value
50+
51+
c = C(5)
52+
print(c.x)
53+
c.x = 6
54+
print(c.x)

0 commit comments

Comments
 (0)