Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
895b1dbd
Commit
895b1dbd
authored
Jul 16, 2020
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests/basics: Split out memoryview slice-assign tests to separate file.
Signed-off-by:
Damien George
<
damien@micropython.org
>
parent
f80b1d85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
48 deletions
+63
-48
tests/basics/memoryview1.py
tests/basics/memoryview1.py
+0
-48
tests/basics/memoryview_slice_assign.py
tests/basics/memoryview_slice_assign.py
+63
-0
No files found.
tests/basics/memoryview1.py
View file @
895b1dbd
...
...
@@ -54,54 +54,6 @@ print(list(m[1:-1]))
m
[
2
]
=
6
print
(
a
)
# test slice assignment between memoryviews
b1
=
bytearray
(
b'1234'
)
b2
=
bytearray
(
b'5678'
)
b3
=
bytearray
(
b'5678'
)
m1
=
memoryview
(
b1
)
m2
=
memoryview
(
b2
)
m3
=
memoryview
(
b3
)
m2
[
1
:
3
]
=
m1
[
0
:
2
]
print
(
b2
)
b3
[
1
:
3
]
=
m1
[
0
:
2
]
print
(
b3
)
m1
[
2
:
4
]
=
b3
[
1
:
3
]
print
(
b1
)
try
:
m2
[
1
:
3
]
=
b1
[
0
:
4
]
except
ValueError
:
print
(
"ValueError"
)
try
:
m2
[
1
:
3
]
=
m1
[
0
:
4
]
except
ValueError
:
print
(
"ValueError"
)
try
:
m2
[
0
:
4
]
=
m1
[
1
:
3
]
except
ValueError
:
print
(
"ValueError"
)
# test memoryview of arrays with items sized larger than 1
a1
=
array
.
array
(
'i'
,
[
0
]
*
5
)
m4
=
memoryview
(
a1
)
a2
=
array
.
array
(
'i'
,
[
3
]
*
5
)
m5
=
memoryview
(
a2
)
m4
[
1
:
3
]
=
m5
[
1
:
3
]
print
(
a1
)
try
:
m4
[
1
:
3
]
=
m2
[
1
:
3
]
except
ValueError
:
print
(
"ValueError"
)
# invalid assignment on RHS
try
:
memoryview
(
array
.
array
(
'i'
))[
0
:
2
]
=
b'1234'
except
ValueError
:
print
(
'ValueError'
)
# invalid attribute
try
:
memoryview
(
b'a'
).
noexist
...
...
tests/basics/memoryview_slice_assign.py
0 → 100644
View file @
895b1dbd
# test slice assignment to memoryview
try
:
memoryview
(
bytearray
(
1
))[:]
=
memoryview
(
bytearray
(
1
))
except
(
NameError
,
TypeError
):
print
(
"SKIP"
)
raise
SystemExit
try
:
import
uarray
as
array
except
ImportError
:
try
:
import
array
except
ImportError
:
print
(
"SKIP"
)
raise
SystemExit
# test slice assignment between memoryviews
b1
=
bytearray
(
b'1234'
)
b2
=
bytearray
(
b'5678'
)
b3
=
bytearray
(
b'5678'
)
m1
=
memoryview
(
b1
)
m2
=
memoryview
(
b2
)
m3
=
memoryview
(
b3
)
m2
[
1
:
3
]
=
m1
[
0
:
2
]
print
(
b2
)
b3
[
1
:
3
]
=
m1
[
0
:
2
]
print
(
b3
)
m1
[
2
:
4
]
=
b3
[
1
:
3
]
print
(
b1
)
# invalid slice assignments
try
:
m2
[
1
:
3
]
=
b1
[
0
:
4
]
except
ValueError
:
print
(
"ValueError"
)
try
:
m2
[
1
:
3
]
=
m1
[
0
:
4
]
except
ValueError
:
print
(
"ValueError"
)
try
:
m2
[
0
:
4
]
=
m1
[
1
:
3
]
except
ValueError
:
print
(
"ValueError"
)
# test memoryview of arrays with items sized larger than 1
a1
=
array
.
array
(
'i'
,
[
0
]
*
5
)
m4
=
memoryview
(
a1
)
a2
=
array
.
array
(
'i'
,
[
3
]
*
5
)
m5
=
memoryview
(
a2
)
m4
[
1
:
3
]
=
m5
[
1
:
3
]
print
(
a1
)
try
:
m4
[
1
:
3
]
=
m2
[
1
:
3
]
except
ValueError
:
print
(
"ValueError"
)
# invalid assignment on RHS
try
:
memoryview
(
array
.
array
(
'i'
))[
0
:
2
]
=
b'1234'
except
ValueError
:
print
(
'ValueError'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment