diff options
| author | Tony DiCola <tony@tonydicola.com> | 2016-10-20 23:01:13 +0000 |
|---|---|---|
| committer | Tony DiCola <tony@tonydicola.com> | 2016-10-20 23:01:13 +0000 |
| commit | 00a44fa36cd1e35a438c4b89b5cef0bc82787c7a (patch) | |
| tree | 4800a6984902e043e3fc437adcdfcd665f83e220 /tests/basics | |
| parent | 1f13f870b8f6554d9cd5570de221a6886e065b64 (diff) | |
| parent | 3967ca7390ff8257728ef6237b93977b63bde41d (diff) | |
Merge remote-tracking branch 'micropython/master'
Conflicts:
README.md - Kept Adafruit README.md intact.
py/emitglue.c - Added xtensa architecture as an OR of the define.
zephyr/README.md - Fixed spelling mistake.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/array1.py | 4 | ||||
| -rw-r--r-- | tests/basics/async_def.py | 16 | ||||
| -rw-r--r-- | tests/basics/async_def.py.exp | 3 | ||||
| -rw-r--r-- | tests/basics/async_with.py | 4 | ||||
| -rw-r--r-- | tests/basics/async_with.py.exp | 1 | ||||
| -rw-r--r-- | tests/basics/builtin_range.py | 6 | ||||
| -rw-r--r-- | tests/basics/del_global.py | 5 | ||||
| -rw-r--r-- | tests/basics/dict1.py | 24 | ||||
| -rw-r--r-- | tests/basics/dict_views.py | 15 | ||||
| -rw-r--r-- | tests/basics/for_range.py | 5 | ||||
| -rw-r--r-- | tests/basics/int_constfolding.py | 5 | ||||
| -rw-r--r-- | tests/basics/slice_attrs.py | 9 | ||||
| -rw-r--r-- | tests/basics/syntaxerror.py | 4 | ||||
| -rw-r--r-- | tests/basics/unpack1.py | 1 |
14 files changed, 101 insertions, 1 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py index e5ea6683c..c45b883c9 100644 --- a/tests/basics/array1.py +++ b/tests/basics/array1.py @@ -21,6 +21,10 @@ print(array.array('i')) print(bool(array.array('i'))) print(bool(array.array('i', [1]))) +# containment, with incorrect type +print('12' in array.array('B', b'12')) +print([] in array.array('B', b'12')) + # bad typecode try: array.array('X') diff --git a/tests/basics/async_def.py b/tests/basics/async_def.py new file mode 100644 index 000000000..e345703d7 --- /dev/null +++ b/tests/basics/async_def.py @@ -0,0 +1,16 @@ +# test async def + +def dec(f): + print('decorator') + return f + +# test definition with a decorator +@dec +async def foo(): + print('foo') + +coro = foo() +try: + coro.send(None) +except StopIteration: + print('StopIteration') diff --git a/tests/basics/async_def.py.exp b/tests/basics/async_def.py.exp new file mode 100644 index 000000000..f555ace99 --- /dev/null +++ b/tests/basics/async_def.py.exp @@ -0,0 +1,3 @@ +decorator +foo +StopIteration diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py index 9eccfd816..5af0c5d95 100644 --- a/tests/basics/async_with.py +++ b/tests/basics/async_with.py @@ -3,6 +3,7 @@ class AContext: async def __aenter__(self): print('enter') + return 1 async def __aexit__(self, exc_type, exc, tb): print('exit', exc_type, exc) @@ -17,7 +18,8 @@ except StopIteration: print('finished') async def g(): - async with AContext(): + async with AContext() as ac: + print(ac) raise ValueError('error') o = g() diff --git a/tests/basics/async_with.py.exp b/tests/basics/async_with.py.exp index 6072a3e0b..d00b18c96 100644 --- a/tests/basics/async_with.py.exp +++ b/tests/basics/async_with.py.exp @@ -3,5 +3,6 @@ body exit None None finished enter +1 exit <class 'ValueError'> error ValueError diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 9110cf12c..59fc0344a 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -50,3 +50,9 @@ try: range(1)[0] = 1 except TypeError: print("TypeError") + +# bad attr (can't store) +try: + range(4).start = 0 +except AttributeError: + print('AttributeError') diff --git a/tests/basics/del_global.py b/tests/basics/del_global.py index 77d11cb3c..d740357b0 100644 --- a/tests/basics/del_global.py +++ b/tests/basics/del_global.py @@ -54,3 +54,8 @@ try: print(c) except NameError: print("NameError") + +a = 1 +b = 2 +c = 3 +del (a, (b, c)) diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py index c70ca588a..20fa9def3 100644 --- a/tests/basics/dict1.py +++ b/tests/basics/dict1.py @@ -16,3 +16,27 @@ while x < 100: d[x] = x x += 1 print(d[50]) + +# equality operator on dicts of different size +print({} == {1:1}) + +# equality operator on dicts of same size but with different keys +print({1:1} == {2:1}) + +# value not found +try: + {}[0] +except KeyError as er: + print('KeyError', er, repr(er), er.args) + +# unsupported unary op +try: + +{} +except TypeError: + print('TypeError') + +# unsupported binary op +try: + {} + {} +except TypeError: + print('TypeError') diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py index fbf63fa0a..7ebcc1f56 100644 --- a/tests/basics/dict_views.py +++ b/tests/basics/dict_views.py @@ -3,4 +3,19 @@ for m in d.items, d.values, d.keys: print(m()) print(list(m())) +# print a view with more than one item +print({1:1, 2:1}.values()) + +# unsupported binary op on a dict values view +try: + {1:1}.values() + 1 +except TypeError: + print('TypeError') + +# unsupported binary op on a dict keys view +try: + {1:1}.keys() + 1 +except TypeError: + print('TypeError') + # set operations still to come diff --git a/tests/basics/for_range.py b/tests/basics/for_range.py index ddff5ebd4..58a8f7caa 100644 --- a/tests/basics/for_range.py +++ b/tests/basics/for_range.py @@ -35,6 +35,11 @@ try: except TypeError: print('TypeError') try: + for x in range(start=0, end=1): + print(x) +except TypeError: + print('TypeError') +try: for x in range(0, 1, step=1): print(x) except TypeError: diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index c01f964da..aa38fa6b8 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -38,3 +38,8 @@ print(-123 // 7, -123 % 7) print(123 // -7, 123 % -7) print(-123 // -7, -123 % -7) +# zero big-num on rhs +print(1 + ((1 << 65) - (1 << 65))) + +# negative big-num on rhs +print(1 + (-(1 << 65))) diff --git a/tests/basics/slice_attrs.py b/tests/basics/slice_attrs.py index 76368a78c..67456ff8e 100644 --- a/tests/basics/slice_attrs.py +++ b/tests/basics/slice_attrs.py @@ -14,3 +14,12 @@ except: A()[1:2:3] + +# test storing to attr (shouldn't be allowed) +class B: + def __getitem__(self, idx): + try: + idx.start = 0 + except AttributeError: + print('AttributeError') +B()[:] diff --git a/tests/basics/syntaxerror.py b/tests/basics/syntaxerror.py index 2ae0183f8..e5cbbac06 100644 --- a/tests/basics/syntaxerror.py +++ b/tests/basics/syntaxerror.py @@ -49,6 +49,9 @@ test_syntax("f[0]**2 = 1") # can't assign to empty tuple test_syntax("() = 1") +# can't have *x on RHS +test_syntax("x = *x") + # can't have multiple *x on LHS test_syntax("*a, *b = c") @@ -76,6 +79,7 @@ test_syntax("continue") test_syntax("return") test_syntax("yield") test_syntax("nonlocal a") +test_syntax("await 1") # error on uPy, warning on CPy #test_syntax("def f():\n a = 1\n global a") diff --git a/tests/basics/unpack1.py b/tests/basics/unpack1.py index 10e01dea0..0e8ec592c 100644 --- a/tests/basics/unpack1.py +++ b/tests/basics/unpack1.py @@ -12,6 +12,7 @@ a, b, c = range(3); print(a, b, c) (a,) = range(1); print(a) (a, b) = range(2); print(a, b) (a, b, c) = range(3); print(a, b, c) +(a, (b, c)) = [-1, range(2)]; print(a, b, c) # lists |
