diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/builtin_slice.py | 37 | ||||
| -rw-r--r-- | tests/micropython/heapalloc_slice.py | 18 | ||||
| -rwxr-xr-x | tests/run-tests.py | 3 |
3 files changed, 56 insertions, 2 deletions
diff --git a/tests/basics/builtin_slice.py b/tests/basics/builtin_slice.py index df84d5c57..5197a7cad 100644 --- a/tests/basics/builtin_slice.py +++ b/tests/basics/builtin_slice.py @@ -1,11 +1,44 @@ # test builtin slice +# ensures that slices passed to user types are heap-allocated and can be +# safely stored as well as not overriden by subsequent slices. + # print slice class A: def __getitem__(self, idx): - print(idx) + print("get", idx) + print("abc"[1:]) + print("get", idx) + return idx + + def __setitem__(self, idx, value): + print("set", idx) + print("abc"[1:]) + print("set", idx) + self.saved_idx = idx + return idx + + def __delitem__(self, idx): + print("del", idx) + print("abc"[1:]) + print("del", idx) return idx -s = A()[1:2:3] + + +a = A() +s = a[1:2:3] +a[4:5:6] = s +del a[7:8:9] + +print(a.saved_idx) + +# nested slicing +print(A()[1 : A()[A()[2:3:4] : 5]]) + +# tuple slicing +a[1:2, 4:5, 7:8] +a[1, 4:5, 7:8, 2] +a[1:2, a[3:4], 5:6] # check type print(type(s) is slice) diff --git a/tests/micropython/heapalloc_slice.py b/tests/micropython/heapalloc_slice.py new file mode 100644 index 000000000..62d96595c --- /dev/null +++ b/tests/micropython/heapalloc_slice.py @@ -0,0 +1,18 @@ +# slice operations that don't require allocation +try: + from micropython import heap_lock, heap_unlock +except (ImportError, AttributeError): + heap_lock = heap_unlock = lambda: 0 + +b = bytearray(range(10)) + +m = memoryview(b) + +heap_lock() + +b[3:5] = b"aa" +m[5:7] = b"bb" + +heap_unlock() + +print(b) diff --git a/tests/run-tests.py b/tests/run-tests.py index 0eaee5278..fe338d7ff 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -855,6 +855,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): "micropython/emg_exc.py" ) # because native doesn't have proper traceback info skip_tests.add( + "micropython/heapalloc_slice.py" + ) # because native doesn't do the stack-allocated slice optimisation + skip_tests.add( "micropython/heapalloc_traceback.py" ) # because native doesn't have proper traceback info skip_tests.add( |
