From e3383e9352ca7704e650b07038207719c60b56fb Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Aug 2017 21:57:36 +0300 Subject: py/stream: seek: Consistently handle negative offset for SEEK_SET. Per POSIX, this is EINVAL, so raises OSError(EINVAL). --- tests/io/bytesio_ext2.py | 13 +++++++++++++ tests/io/bytesio_ext2.py.exp | 1 + 2 files changed, 14 insertions(+) create mode 100644 tests/io/bytesio_ext2.py create mode 100644 tests/io/bytesio_ext2.py.exp (limited to 'tests') diff --git a/tests/io/bytesio_ext2.py b/tests/io/bytesio_ext2.py new file mode 100644 index 000000000..c07ad900c --- /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 000000000..b52e4978a --- /dev/null +++ b/tests/io/bytesio_ext2.py.exp @@ -0,0 +1 @@ +OSError(22,) -- cgit v1.2.3