summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/async_await.py17
-rw-r--r--tests/basics/async_await.py.exp32
-rw-r--r--tests/basics/async_await2.py27
-rw-r--r--tests/basics/async_await2.py.exp5
-rw-r--r--tests/basics/async_for.py29
-rw-r--r--tests/basics/async_for.py.exp10
-rw-r--r--tests/basics/async_for2.py48
-rw-r--r--tests/basics/async_for2.py.exp36
-rw-r--r--tests/basics/async_with.py17
-rw-r--r--tests/basics/async_with.py.exp4
-rw-r--r--tests/basics/async_with2.py37
-rw-r--r--tests/basics/async_with2.py.exp17
-rw-r--r--tests/basics/class_store_class.py2
-rw-r--r--tests/basics/dict1.py6
-rw-r--r--tests/basics/fun_calldblstar2.py13
-rw-r--r--tests/basics/gen_yield_from_stopped.py18
-rw-r--r--tests/basics/namedtuple1.py2
-rw-r--r--tests/basics/ordereddict1.py2
-rw-r--r--tests/bench/var-8-namedtuple-1st.py2
-rw-r--r--tests/bench/var-8.1-namedtuple-5th.py2
-rw-r--r--tests/extmod/ure_split.py10
-rw-r--r--tests/extmod/ure_split_empty.py19
-rw-r--r--tests/extmod/ure_split_empty.py.exp3
-rw-r--r--tests/io/buffered_writer.py2
-rw-r--r--tests/io/stringio1.py5
-rw-r--r--tests/io/stringio_with.py5
-rw-r--r--tests/misc/print_exception.py5
-rw-r--r--tests/misc/recursive_data.py2
-rwxr-xr-xtests/run-bench-tests2
-rwxr-xr-xtests/run-tests3
30 files changed, 357 insertions, 25 deletions
diff --git a/tests/basics/async_await.py b/tests/basics/async_await.py
new file mode 100644
index 0000000000..23b3ba9378
--- /dev/null
+++ b/tests/basics/async_await.py
@@ -0,0 +1,17 @@
+# test basic await expression
+# adapted from PEP0492
+
+async def abinary(n):
+ print(n)
+ if n <= 0:
+ return 1
+ l = await abinary(n - 1)
+ r = await abinary(n - 1)
+ return l + 1 + r
+
+o = abinary(4)
+try:
+ while True:
+ o.send(None)
+except StopIteration:
+ print('finished')
diff --git a/tests/basics/async_await.py.exp b/tests/basics/async_await.py.exp
new file mode 100644
index 0000000000..b51c388a93
--- /dev/null
+++ b/tests/basics/async_await.py.exp
@@ -0,0 +1,32 @@
+4
+3
+2
+1
+0
+0
+1
+0
+0
+2
+1
+0
+0
+1
+0
+0
+3
+2
+1
+0
+0
+1
+0
+0
+2
+1
+0
+0
+1
+0
+0
+finished
diff --git a/tests/basics/async_await2.py b/tests/basics/async_await2.py
new file mode 100644
index 0000000000..129d3751a5
--- /dev/null
+++ b/tests/basics/async_await2.py
@@ -0,0 +1,27 @@
+# test await expression
+
+import sys
+if sys.implementation.name == 'micropython':
+ # uPy allows normal generators to be awaitables
+ coroutine = lambda f: f
+else:
+ import types
+ coroutine = types.coroutine
+
+@coroutine
+def wait(value):
+ print('wait value:', value)
+ msg = yield 'message from wait(%u)' % value
+ print('wait got back:', msg)
+ return 10
+
+async def f():
+ x = await wait(1)**2
+ print('x =', x)
+
+coro = f()
+print('return from send:', coro.send(None))
+try:
+ coro.send('message from main')
+except StopIteration:
+ print('got StopIteration')
diff --git a/tests/basics/async_await2.py.exp b/tests/basics/async_await2.py.exp
new file mode 100644
index 0000000000..fc9ff0aa53
--- /dev/null
+++ b/tests/basics/async_await2.py.exp
@@ -0,0 +1,5 @@
+wait value: 1
+return from send: message from wait(1)
+wait got back: message from main
+x = 100
+got StopIteration
diff --git a/tests/basics/async_for.py b/tests/basics/async_for.py
new file mode 100644
index 0000000000..6b4e136d59
--- /dev/null
+++ b/tests/basics/async_for.py
@@ -0,0 +1,29 @@
+# test basic async for execution
+# example taken from PEP0492
+
+class AsyncIteratorWrapper:
+ def __init__(self, obj):
+ print('init')
+ self._it = iter(obj)
+
+ async def __aiter__(self):
+ print('aiter')
+ return self
+
+ async def __anext__(self):
+ print('anext')
+ try:
+ value = next(self._it)
+ except StopIteration:
+ raise StopAsyncIteration
+ return value
+
+async def coro():
+ async for letter in AsyncIteratorWrapper('abc'):
+ print(letter)
+
+o = coro()
+try:
+ o.send(None)
+except StopIteration:
+ print('finished')
diff --git a/tests/basics/async_for.py.exp b/tests/basics/async_for.py.exp
new file mode 100644
index 0000000000..1f728a66c8
--- /dev/null
+++ b/tests/basics/async_for.py.exp
@@ -0,0 +1,10 @@
+init
+aiter
+anext
+a
+anext
+b
+anext
+c
+anext
+finished
diff --git a/tests/basics/async_for2.py b/tests/basics/async_for2.py
new file mode 100644
index 0000000000..89584fcb10
--- /dev/null
+++ b/tests/basics/async_for2.py
@@ -0,0 +1,48 @@
+# test waiting within "async for" aiter/anext functions
+
+import sys
+if sys.implementation.name == 'micropython':
+ # uPy allows normal generators to be awaitables
+ coroutine = lambda f: f
+else:
+ import types
+ coroutine = types.coroutine
+
+@coroutine
+def f(x):
+ print('f start:', x)
+ yield x + 1
+ yield x + 2
+ return x + 3
+
+class ARange:
+ def __init__(self, high):
+ print('init')
+ self.cur = 0
+ self.high = high
+
+ async def __aiter__(self):
+ print('aiter')
+ print('f returned:', await f(10))
+ return self
+
+ async def __anext__(self):
+ print('anext')
+ print('f returned:', await f(20))
+ if self.cur < self.high:
+ val = self.cur
+ self.cur += 1
+ return val
+ else:
+ raise StopAsyncIteration
+
+async def coro():
+ async for x in ARange(4):
+ print('x', x)
+
+o = coro()
+try:
+ while True:
+ print('coro yielded:', o.send(None))
+except StopIteration:
+ print('finished')
diff --git a/tests/basics/async_for2.py.exp b/tests/basics/async_for2.py.exp
new file mode 100644
index 0000000000..886232f7ba
--- /dev/null
+++ b/tests/basics/async_for2.py.exp
@@ -0,0 +1,36 @@
+init
+aiter
+f start: 10
+coro yielded: 11
+coro yielded: 12
+f returned: 13
+anext
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+x 0
+anext
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+x 1
+anext
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+x 2
+anext
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+x 3
+anext
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+finished
diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py
new file mode 100644
index 0000000000..742f9ba993
--- /dev/null
+++ b/tests/basics/async_with.py
@@ -0,0 +1,17 @@
+# test simple async with execution
+
+class AContext:
+ async def __aenter__(self):
+ print('enter')
+ async def __aexit__(self, exc_type, exc, tb):
+ print('exit')
+
+async def f():
+ async with AContext():
+ print('body')
+
+o = f()
+try:
+ o.send(None)
+except StopIteration:
+ print('finished')
diff --git a/tests/basics/async_with.py.exp b/tests/basics/async_with.py.exp
new file mode 100644
index 0000000000..1e9176af7b
--- /dev/null
+++ b/tests/basics/async_with.py.exp
@@ -0,0 +1,4 @@
+enter
+body
+exit
+finished
diff --git a/tests/basics/async_with2.py b/tests/basics/async_with2.py
new file mode 100644
index 0000000000..0ebec489fe
--- /dev/null
+++ b/tests/basics/async_with2.py
@@ -0,0 +1,37 @@
+# test waiting within async with enter/exit functions
+
+import sys
+if sys.implementation.name == 'micropython':
+ # uPy allows normal generators to be awaitables
+ coroutine = lambda f: f
+else:
+ import types
+ coroutine = types.coroutine
+
+@coroutine
+def f(x):
+ print('f start:', x)
+ yield x + 1
+ yield x + 2
+ return x + 3
+
+class AContext:
+ async def __aenter__(self):
+ print('enter')
+ print('f returned:', await f(10))
+ async def __aexit__(self, exc_type, exc, tb):
+ print('exit')
+ print('f returned:', await f(20))
+
+async def coro():
+ async with AContext():
+ print('body start')
+ print('body f returned:', await f(30))
+ print('body end')
+
+o = coro()
+try:
+ while True:
+ print('coro yielded:', o.send(None))
+except StopIteration:
+ print('finished')
diff --git a/tests/basics/async_with2.py.exp b/tests/basics/async_with2.py.exp
new file mode 100644
index 0000000000..dd5a1c549a
--- /dev/null
+++ b/tests/basics/async_with2.py.exp
@@ -0,0 +1,17 @@
+enter
+f start: 10
+coro yielded: 11
+coro yielded: 12
+f returned: 13
+body start
+f start: 30
+coro yielded: 31
+coro yielded: 32
+body f returned: 33
+body end
+exit
+f start: 20
+coro yielded: 21
+coro yielded: 22
+f returned: 23
+finished
diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py
index 09a8e8bc4d..10b94d3c6a 100644
--- a/tests/basics/class_store_class.py
+++ b/tests/basics/class_store_class.py
@@ -5,7 +5,7 @@
try:
from collections import namedtuple
except ImportError:
- from _collections import namedtuple
+ from ucollections import namedtuple
_DefragResultBase = namedtuple('DefragResult', [ 'foo', 'bar' ])
diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py
index f189266b4d..c70ca588a7 100644
--- a/tests/basics/dict1.py
+++ b/tests/basics/dict1.py
@@ -6,10 +6,10 @@ d[2] = 123
print(d)
d = {1:2}
d[3] = 3
-print(d)
+print(len(d), d[1], d[3])
d[1] = 0
-print(d)
-print(d[1])
+print(len(d), d[1], d[3])
+print(str(d) == '{1: 0, 3: 3}' or str(d) == '{3: 3, 1: 0}')
x = 1
while x < 100:
diff --git a/tests/basics/fun_calldblstar2.py b/tests/basics/fun_calldblstar2.py
new file mode 100644
index 0000000000..cf982ef5b8
--- /dev/null
+++ b/tests/basics/fun_calldblstar2.py
@@ -0,0 +1,13 @@
+# test passing a string object as the key for a keyword argument
+
+# they key in this dict is a string object and is not interned
+args = {'thisisaverylongargumentname': 123}
+
+# when this string is executed it will intern the keyword argument
+exec("def foo(*,thisisaverylongargumentname=1):\n print(thisisaverylongargumentname)")
+
+# test default arg
+foo()
+
+# the string from the dict should match the interned keyword argument
+foo(**args)
diff --git a/tests/basics/gen_yield_from_stopped.py b/tests/basics/gen_yield_from_stopped.py
new file mode 100644
index 0000000000..468679b615
--- /dev/null
+++ b/tests/basics/gen_yield_from_stopped.py
@@ -0,0 +1,18 @@
+# Yielding from stopped generator is ok and results in None
+
+def gen():
+ return 1
+ # This yield is just to make this a generator
+ yield
+
+f = gen()
+
+def run():
+ print((yield from f))
+ print((yield from f))
+ print((yield from f))
+
+try:
+ next(run())
+except StopIteration:
+ print("StopIteration")
diff --git a/tests/basics/namedtuple1.py b/tests/basics/namedtuple1.py
index ae795ba6de..dfbb79f2eb 100644
--- a/tests/basics/namedtuple1.py
+++ b/tests/basics/namedtuple1.py
@@ -1,7 +1,7 @@
try:
from collections import namedtuple
except ImportError:
- from _collections import namedtuple
+ from ucollections import namedtuple
T = namedtuple("Tup", ["foo", "bar"])
# CPython prints fully qualified name, what we don't bother to do so far
diff --git a/tests/basics/ordereddict1.py b/tests/basics/ordereddict1.py
index 26d0effd53..5e8b2413b6 100644
--- a/tests/basics/ordereddict1.py
+++ b/tests/basics/ordereddict1.py
@@ -2,7 +2,7 @@ try:
from collections import OrderedDict
except ImportError:
try:
- from _collections import OrderedDict
+ from ucollections import OrderedDict
except ImportError:
print("SKIP")
import sys
diff --git a/tests/bench/var-8-namedtuple-1st.py b/tests/bench/var-8-namedtuple-1st.py
index f3f36f415a..d862480a51 100644
--- a/tests/bench/var-8-namedtuple-1st.py
+++ b/tests/bench/var-8-namedtuple-1st.py
@@ -1,5 +1,5 @@
import bench
-from _collections import namedtuple
+from ucollections import namedtuple
T = namedtuple("Tup", ["num", "bar"])
diff --git a/tests/bench/var-8.1-namedtuple-5th.py b/tests/bench/var-8.1-namedtuple-5th.py
index b6bdc8d795..0bcf661803 100644
--- a/tests/bench/var-8.1-namedtuple-5th.py
+++ b/tests/bench/var-8.1-namedtuple-5th.py
@@ -1,5 +1,5 @@
import bench
-from _collections import namedtuple
+from ucollections import namedtuple
T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"])
diff --git a/tests/extmod/ure_split.py b/tests/extmod/ure_split.py
index 3f7718813f..620fd9052b 100644
--- a/tests/extmod/ure_split.py
+++ b/tests/extmod/ure_split.py
@@ -19,16 +19,6 @@ r = re.compile(" +")
s = r.split("a b c foobar", 2)
print(s)
-r = re.compile(" *")
-s = r.split("a b c foobar")
-# TODO - no idea how this is supposed to work, per docs, empty match == stop
-# splitting, so CPython code apparently does some dirty magic.
-#print(s)
-
-r = re.compile("x*")
-s = r.split("foo")
-print(s)
-
r = re.compile("[a-f]+")
s = r.split("0a3b9")
print(s)
diff --git a/tests/extmod/ure_split_empty.py b/tests/extmod/ure_split_empty.py
new file mode 100644
index 0000000000..6f31e6dc6c
--- /dev/null
+++ b/tests/extmod/ure_split_empty.py
@@ -0,0 +1,19 @@
+# test splitting with pattern matches that can be empty
+#
+# CPython 3.5 issues a FutureWarning for these tests because their
+# behaviour will change in a future version. MicroPython just stops
+# splitting as soon as an empty match is found.
+
+import ure as re
+
+r = re.compile(" *")
+s = r.split("a b c foobar")
+print(s)
+
+r = re.compile("x*")
+s = r.split("foo")
+print(s)
+
+r = re.compile("x*")
+s = r.split("axbc")
+print(s)
diff --git a/tests/extmod/ure_split_empty.py.exp b/tests/extmod/ure_split_empty.py.exp
new file mode 100644
index 0000000000..42cfea0d5d
--- /dev/null
+++ b/tests/extmod/ure_split_empty.py.exp
@@ -0,0 +1,3 @@
+['a b c foobar']
+['foo']
+['axbc']
diff --git a/tests/io/buffered_writer.py b/tests/io/buffered_writer.py
index 0fe8a77309..afeaa839c1 100644
--- a/tests/io/buffered_writer.py
+++ b/tests/io/buffered_writer.py
@@ -1,4 +1,4 @@
-import _io as io
+import uio as io
try:
io.BytesIO
diff --git a/tests/io/stringio1.py b/tests/io/stringio1.py
index 22f561f299..fa50f282e1 100644
--- a/tests/io/stringio1.py
+++ b/tests/io/stringio1.py
@@ -1,4 +1,7 @@
-import _io as io
+try:
+ import uio as io
+except ImportError:
+ import io
a = io.StringIO()
print('io.StringIO' in repr(a))
diff --git a/tests/io/stringio_with.py b/tests/io/stringio_with.py
index becb564dfd..c35975445d 100644
--- a/tests/io/stringio_with.py
+++ b/tests/io/stringio_with.py
@@ -1,4 +1,7 @@
-import _io as io
+try:
+ import uio as io
+except ImportError:
+ import io
# test __enter__/__exit__
with io.StringIO() as b:
diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py
index 1d3ca4cf46..9baac713ee 100644
--- a/tests/misc/print_exception.py
+++ b/tests/misc/print_exception.py
@@ -1,4 +1,7 @@
-import _io as io # uPy does not have io module builtin
+try:
+ import uio as io
+except ImportError:
+ import io
import sys
if hasattr(sys, 'print_exception'):
print_exception = sys.print_exception
diff --git a/tests/misc/recursive_data.py b/tests/misc/recursive_data.py
index 53fb30f9ff..0de93acb89 100644
--- a/tests/misc/recursive_data.py
+++ b/tests/misc/recursive_data.py
@@ -1,5 +1,5 @@
# This tests that printing recursive data structure doesn't lead to segfault.
-import _io as io
+import uio as io
l = [1, 2, 3, None]
l[-1] = l
diff --git a/tests/run-bench-tests b/tests/run-bench-tests
index 62f0833f41..1e5e7804be 100755
--- a/tests/run-bench-tests
+++ b/tests/run-bench-tests
@@ -22,7 +22,7 @@ def run_tests(pyb, test_dict):
test_count = 0
testcase_count = 0
- for base_test, tests in test_dict.items():
+ for base_test, tests in sorted(test_dict.items()):
print(base_test + ":")
for test_file in tests:
diff --git a/tests/run-tests b/tests/run-tests
index 0185fbda68..fd4063dc91 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -241,8 +241,9 @@ def run_tests(pyb, tests, args):
# Some tests are known to fail with native emitter
# Remove them from the below when they work
if args.emit == 'native':
- skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_throw generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield
+ skip_tests.update({'basics/%s.py' % t for t in 'gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_stopped gen_yield_from_throw generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send'.split()}) # require yield
skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class globals_del string_join'.split()}) # require yield
+ skip_tests.update({'basics/async_%s.py' % t for t in 'await await2 for for2 with with2'.split()}) # require yield
skip_tests.update({'basics/%s.py' % t for t in 'try_reraise try_reraise2'.split()}) # require raise_varargs
skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support
skip_tests.add('basics/array_construct2.py') # requires generators