summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/builtin_hash.py1
-rw-r--r--tests/basics/list1.py6
-rw-r--r--tests/basics/list_mult.py6
-rw-r--r--tests/basics/list_pop.py6
-rw-r--r--tests/basics/slice_bignum.py5
-rw-r--r--tests/basics/special_methods.py146
-rw-r--r--tests/basics/try_finally_loops.py8
-rw-r--r--tests/basics/tuple1.py15
-rw-r--r--tests/basics/tuple_mult.py6
9 files changed, 199 insertions, 0 deletions
diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py
index c9731a3b59..ffea08e575 100644
--- a/tests/basics/builtin_hash.py
+++ b/tests/basics/builtin_hash.py
@@ -3,6 +3,7 @@
print(hash(False))
print(hash(True))
print({():1}) # hash tuple
+print({(1,):1}) # hash non-empty tuple
print({1 << 66:1}) # hash big int
print({-(1 << 66):2}) # hash negative big int
print(hash in {hash:1}) # hash function
diff --git a/tests/basics/list1.py b/tests/basics/list1.py
index c8317baa3d..fa426c0e58 100644
--- a/tests/basics/list1.py
+++ b/tests/basics/list1.py
@@ -22,3 +22,9 @@ print(x)
print(x[1:])
print(x[:-1])
print(x[2:3])
+
+# unsupported type on RHS of add
+try:
+ [] + None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py
index 16948f74c2..548f88534e 100644
--- a/tests/basics/list_mult.py
+++ b/tests/basics/list_mult.py
@@ -10,3 +10,9 @@ for i in (-4, -2, 0, 2, 4):
a = [1, 2, 3]
c = a * 3
print(a, c)
+
+# unsupported type on RHS
+try:
+ [] * None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/list_pop.py b/tests/basics/list_pop.py
index bb2ccc6d67..87ed456f85 100644
--- a/tests/basics/list_pop.py
+++ b/tests/basics/list_pop.py
@@ -9,3 +9,9 @@ except IndexError:
print("IndexError raised")
else:
raise AssertionError("No IndexError raised")
+
+# popping such that list storage shrinks (tests implementation detail of uPy)
+l = list(range(20))
+for i in range(len(l)):
+ l.pop()
+print(l)
diff --git a/tests/basics/slice_bignum.py b/tests/basics/slice_bignum.py
new file mode 100644
index 0000000000..cc820522b0
--- /dev/null
+++ b/tests/basics/slice_bignum.py
@@ -0,0 +1,5 @@
+# test slicing when arguments are bignums
+
+print(list(range(10))[(1<<66)>>65:])
+print(list(range(10))[:(1<<66)>>65])
+print(list(range(10))[::(1<<66)>>65])
diff --git a/tests/basics/special_methods.py b/tests/basics/special_methods.py
new file mode 100644
index 0000000000..1df7a7c4c7
--- /dev/null
+++ b/tests/basics/special_methods.py
@@ -0,0 +1,146 @@
+class Cud():
+
+ def __init__(self):
+ print("__init__ called")
+
+ def __repr__(self):
+ print("__repr__ called")
+ return ""
+
+ def __lt__(self, other):
+ print("__lt__ called")
+
+ def __le__(self, other):
+ print("__le__ called")
+
+ def __eq__(self, other):
+ print("__eq__ called")
+
+ def __ne__(self, other):
+ print("__ne__ called")
+
+ def __ge__(self, other):
+ print("__ge__ called")
+
+ def __gt__(self, other):
+ print("__gt__ called")
+
+ def __abs__(self):
+ print("__abs__ called")
+
+ def __add__(self, other):
+ print("__add__ called")
+
+ def __and__(self, other):
+ print("__and__ called")
+
+ def __floordiv__(self, other):
+ print("__floordiv__ called")
+
+ def __index__(self, other):
+ print("__index__ called")
+
+ def __inv__(self):
+ print("__inv__ called")
+
+ def __invert__(self):
+ print("__invert__ called")
+
+ def __lshift__(self, val):
+ print("__lshift__ called")
+
+ def __mod__(self, val):
+ print("__mod__ called")
+
+ def __mul__(self, other):
+ print("__mul__ called")
+
+ def __matmul__(self, other):
+ print("__matmul__ called")
+
+ def __neg__(self):
+ print("__neg__ called")
+
+ def __or__(self, other):
+ print("__or__ called")
+
+ def __pos__(self):
+ print("__pos__ called")
+
+ def __pow__(self, val):
+ print("__pow__ called")
+
+ def __rshift__(self, val):
+ print("__rshift__ called")
+
+ def __sub__(self, other):
+ print("__sub__ called")
+
+ def __truediv__(self, other):
+ print("__truediv__ called")
+
+ def __div__(self, other):
+ print("__div__ called")
+
+ def __xor__(self, other):
+ print("__xor__ called")
+
+ def __iadd__(self, other):
+ print("__iadd__ called")
+ return self
+
+ def __isub__(self, other):
+ print("__isub__ called")
+ return self
+
+cud1 = Cud()
+cud2 = Cud()
+
+str(cud1)
+cud1 < cud2
+cud1 <= cud2
+cud1 == cud2
+cud1 >= cud2
+cud1 > cud2
+cud1 + cud2
+cud1 - cud2
+
+# the following require MICROPY_PY_ALL_SPECIAL_METHODS
++cud1
+-cud1
+~cud1
+cud1 * cud2
+cud1 / cud2
+cud2 // cud1
+cud1 += cud2
+cud1 -= cud2
+
+# TODO: the following operations are not supported on every ports
+#
+# ne is not supported, !(eq) is called instead
+#cud1 != cud2
+#
+# binary and is not supported
+# cud1 & cud2
+#
+# binary lshift is not supported
+# cud1<<1
+#
+# modulus is not supported
+# cud1 % 2
+#
+# binary or is not supported
+# cud1 | cud2
+#
+# pow is not supported
+# cud1**2
+#
+# rshift is not suported
+# cud1>>1
+#
+# xor is not supported
+# cud1^cud2
+#
+# in the followin test, cpython still calls __eq__
+# cud3=cud1
+# cud3==cud1
diff --git a/tests/basics/try_finally_loops.py b/tests/basics/try_finally_loops.py
index 28a8373dc0..06a6b4a0ce 100644
--- a/tests/basics/try_finally_loops.py
+++ b/tests/basics/try_finally_loops.py
@@ -33,3 +33,11 @@ for i in range(4):
print('here')
finally:
print('finnaly 3')
+
+# break from within try-finally, within for-loop
+for i in [1]:
+ try:
+ print(i)
+ break
+ finally:
+ print('finally 4')
diff --git a/tests/basics/tuple1.py b/tests/basics/tuple1.py
index 53eac2a306..2993391d53 100644
--- a/tests/basics/tuple1.py
+++ b/tests/basics/tuple1.py
@@ -16,3 +16,18 @@ print(x[:-1])
print(x[2:3])
print(x + (10, 100, 10000))
+
+# construction of tuple from large iterator (tests implementation detail of uPy)
+print(tuple(range(20)))
+
+# unsupported unary operation
+try:
+ +()
+except TypeError:
+ print('TypeError')
+
+# unsupported type on RHS of add
+try:
+ () + None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py
index 0f52bce44e..b128b29689 100644
--- a/tests/basics/tuple_mult.py
+++ b/tests/basics/tuple_mult.py
@@ -10,3 +10,9 @@ for i in (-4, -2, 0, 2, 4):
a = (1, 2, 3)
c = a * 3
print(a, c)
+
+# unsupported type on RHS
+try:
+ () * None
+except TypeError:
+ print('TypeError')