summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-08-20 21:57:36 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-08-20 22:02:41 +0300
commite3383e9352ca7704e650b07038207719c60b56fb (patch)
tree92ed2d9aab2ef2046ffd913b77309cf515236a63 /tests
parent0cd9ab77550eada4def492a3a25286ead71a3b24 (diff)
downloadmicropython-e3383e9352ca7704e650b07038207719c60b56fb.tar.gz
micropython-e3383e9352ca7704e650b07038207719c60b56fb.zip
py/stream: seek: Consistently handle negative offset for SEEK_SET.
Per POSIX, this is EINVAL, so raises OSError(EINVAL).
Diffstat (limited to 'tests')
-rw-r--r--tests/io/bytesio_ext2.py13
-rw-r--r--tests/io/bytesio_ext2.py.exp1
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/io/bytesio_ext2.py b/tests/io/bytesio_ext2.py
new file mode 100644
index 0000000000..c07ad900c9
--- /dev/null
+++ b/tests/io/bytesio_ext2.py
@@ -0,0 +1,13 @@
+try:
+ import uio as io
+except ImportError:
+ import io
+
+a = io.BytesIO(b"foobar")
+try:
+ a.seek(-10)
+except Exception as e:
+ # CPython throws ValueError, but MicroPython has consistent stream
+ # interface, so BytesIO raises the same error as a real file, which
+ # is OSError(EINVAL).
+ print(repr(e))
diff --git a/tests/io/bytesio_ext2.py.exp b/tests/io/bytesio_ext2.py.exp
new file mode 100644
index 0000000000..b52e4978aa
--- /dev/null
+++ b/tests/io/bytesio_ext2.py.exp
@@ -0,0 +1 @@
+OSError(22,)