summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 19:00:27 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 19:00:27 +0100
commite2a48b66c2a94375d3af00500073e05a5e5fd75a (patch)
tree1dcabe04ee9b702be116b88c15ed6e0e36594b70 /tests
parent777b0f32f459dbf5aac051eab3d91abbc6505501 (diff)
downloadmicropython-e2a48b66c2a94375d3af00500073e05a5e5fd75a.tar.gz
micropython-e2a48b66c2a94375d3af00500073e05a5e5fd75a.zip
tests: Add property test.
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/property.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/basics/property.py b/tests/basics/property.py
new file mode 100644
index 0000000000..7f3c833ad3
--- /dev/null
+++ b/tests/basics/property.py
@@ -0,0 +1,54 @@
+class A:
+ def __init__(self, x):
+ self._x = x
+
+ @property
+ def x(self):
+ print("x get")
+ return self._x
+
+a = A(1)
+print(a.x)
+
+try:
+ a.x = 2
+except AttributeError:
+ print("AttributeError")
+
+class B:
+ def __init__(self, x):
+ self._x = x
+
+ def xget(self):
+ print("x get")
+ return self._x
+
+ def xset(self, value):
+ print("x set")
+ self._x = value
+
+ x = property(xget, xset)
+
+b = B(3)
+print(b.x)
+b.x = 4
+print(b.x)
+
+class C:
+ def __init__(self, x):
+ self._x = x
+
+ @property
+ def x(self):
+ print("x get")
+ return self._x
+
+ @x.setter
+ def x(self, value):
+ print("x set")
+ self._x = value
+
+c = C(5)
+print(c.x)
+c.x = 6
+print(c.x)