summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-30 23:34:25 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-30 23:34:25 +0100
commitdddf5bd3307807dab6b88a0f211ee0a45cae7c50 (patch)
tree83e591f365c0ebf0716e134ad1bc2af1b2b4f732 /tests/basics
parentf4b7e9bd2e72ac040cb242617e08808bbc0d120a (diff)
parent37977b7b27a293aa6ae10726203d81aa0f074566 (diff)
downloadmicropython-dddf5bd3307807dab6b88a0f211ee0a45cae7c50.tar.gz
micropython-dddf5bd3307807dab6b88a0f211ee0a45cae7c50.zip
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/subclass-native1.py31
-rw-r--r--tests/basics/subclass-native2.py37
-rw-r--r--tests/basics/subclass-native3.py8
-rw-r--r--tests/basics/subclass-native4.py9
4 files changed, 85 insertions, 0 deletions
diff --git a/tests/basics/subclass-native1.py b/tests/basics/subclass-native1.py
new file mode 100644
index 0000000000..a176893425
--- /dev/null
+++ b/tests/basics/subclass-native1.py
@@ -0,0 +1,31 @@
+class mylist(list):
+ pass
+
+a = mylist([1, 2, 5])
+# Test setting instance attr
+a.attr = "something"
+# Test base type __str__
+print(a)
+# Test getting instance attr
+print(a.attr)
+# Test base type ->subscr
+print(a[-1])
+a[0] = -1
+print(a)
+# Test another base type unary op
+print(len(a))
+
+# Test binary op of base type, with 2nd arg being raw base type
+print(a + [20, 30, 40])
+# Test binary op of base type, with 2nd arg being same class as 1st arg
+# TODO: Faults
+#print(a + a)
+
+def foo():
+ print("hello from foo")
+
+try:
+ class myfunc(type(foo)):
+ pass
+except TypeError:
+ print("TypeError")
diff --git a/tests/basics/subclass-native2.py b/tests/basics/subclass-native2.py
new file mode 100644
index 0000000000..749bf969cf
--- /dev/null
+++ b/tests/basics/subclass-native2.py
@@ -0,0 +1,37 @@
+class Base1:
+ def __init__(self, *args):
+ print("Base1.__init__",args)
+
+class Clist1(Base1, list):
+ pass
+
+class Ctuple1(Base1, tuple):
+ pass
+
+a = Clist1()
+print(len(a))
+a = Clist1([1, 2, 3])
+print(len(a))
+
+a = Ctuple1()
+print(len(a))
+a = Ctuple1([1, 2, 3])
+# TODO: Faults
+#print(len(a))
+
+print("---")
+
+class Clist2(list, Base1):
+ pass
+
+class Ctuple2(tuple, Base1):
+ pass
+a = Clist2()
+print(len(a))
+a = Clist2([1, 2, 3])
+print(len(a))
+
+#a = Ctuple2()
+#print(len(a))
+#a = Ctuple2([1, 2, 3])
+#print(len(a))
diff --git a/tests/basics/subclass-native3.py b/tests/basics/subclass-native3.py
new file mode 100644
index 0000000000..5d443cf5cd
--- /dev/null
+++ b/tests/basics/subclass-native3.py
@@ -0,0 +1,8 @@
+class MyExc(Exception):
+ pass
+
+e = MyExc(100, "Some error")
+print(e)
+# TODO: Prints native base class name
+#print(repr(e))
+print(e.args)
diff --git a/tests/basics/subclass-native4.py b/tests/basics/subclass-native4.py
new file mode 100644
index 0000000000..b426793f59
--- /dev/null
+++ b/tests/basics/subclass-native4.py
@@ -0,0 +1,9 @@
+# Test calling non-special method inherited from native type
+
+class mylist(list):
+ pass
+
+l = mylist([1, 2, 3])
+print(l)
+l.append(10)
+print(l)