summaryrefslogtreecommitdiff
path: root/tests/io
diff options
context:
space:
mode:
Diffstat (limited to 'tests/io')
-rw-r--r--tests/io/buffered_writer.py9
-rw-r--r--tests/io/buffered_writer.py.exp1
-rw-r--r--tests/io/bytesio_cow.py20
-rw-r--r--tests/io/bytesio_ext.py4
-rw-r--r--tests/io/open_append.py3
-rw-r--r--tests/io/open_plus.py3
-rw-r--r--tests/io/resource_stream.py15
-rw-r--r--tests/io/resource_stream.py.exp2
-rw-r--r--tests/io/write_ext.py3
9 files changed, 52 insertions, 8 deletions
diff --git a/tests/io/buffered_writer.py b/tests/io/buffered_writer.py
index afeaa839c..c2cedb991 100644
--- a/tests/io/buffered_writer.py
+++ b/tests/io/buffered_writer.py
@@ -4,9 +4,8 @@ try:
io.BytesIO
io.BufferedWriter
except AttributeError:
- import sys
print('SKIP')
- sys.exit()
+ raise SystemExit
bts = io.BytesIO()
buf = io.BufferedWriter(bts, 8)
@@ -20,3 +19,9 @@ buf.flush()
print(bts.getvalue())
buf.flush()
print(bts.getvalue())
+
+# special case when alloc is a factor of total buffer length
+bts = io.BytesIO()
+buf = io.BufferedWriter(bts, 1)
+buf.write(b"foo")
+print(bts.getvalue())
diff --git a/tests/io/buffered_writer.py.exp b/tests/io/buffered_writer.py.exp
index 1309487e1..d086935a9 100644
--- a/tests/io/buffered_writer.py.exp
+++ b/tests/io/buffered_writer.py.exp
@@ -2,3 +2,4 @@ b''
b'foobarfo'
b'foobarfoobar'
b'foobarfoobar'
+b'foo'
diff --git a/tests/io/bytesio_cow.py b/tests/io/bytesio_cow.py
new file mode 100644
index 000000000..92654a000
--- /dev/null
+++ b/tests/io/bytesio_cow.py
@@ -0,0 +1,20 @@
+# Make sure that write operations on io.BytesIO don't
+# change original object it was constructed from.
+try:
+ import uio as io
+except ImportError:
+ import io
+
+b = b"foobar"
+
+a = io.BytesIO(b)
+a.write(b"1")
+print(b)
+print(a.getvalue())
+
+b = bytearray(b"foobar")
+
+a = io.BytesIO(b)
+a.write(b"1")
+print(b)
+print(a.getvalue())
diff --git a/tests/io/bytesio_ext.py b/tests/io/bytesio_ext.py
index e827d1409..e454b2fd9 100644
--- a/tests/io/bytesio_ext.py
+++ b/tests/io/bytesio_ext.py
@@ -4,6 +4,10 @@ try:
except ImportError:
import io
+a = io.BytesIO(b"foobar")
+a.seek(10)
+print(a.read(10))
+
a = io.BytesIO()
print(a.seek(8))
a.write(b"123")
diff --git a/tests/io/open_append.py b/tests/io/open_append.py
index 2120b72f0..a696823bc 100644
--- a/tests/io/open_append.py
+++ b/tests/io/open_append.py
@@ -1,4 +1,3 @@
-import sys
try:
import uos as os
except ImportError:
@@ -6,7 +5,7 @@ except ImportError:
if not hasattr(os, "unlink"):
print("SKIP")
- sys.exit()
+ raise SystemExit
# cleanup in case testfile exists
try:
diff --git a/tests/io/open_plus.py b/tests/io/open_plus.py
index 98598ee67..bba96fa2f 100644
--- a/tests/io/open_plus.py
+++ b/tests/io/open_plus.py
@@ -1,4 +1,3 @@
-import sys
try:
import uos as os
except ImportError:
@@ -6,7 +5,7 @@ except ImportError:
if not hasattr(os, "unlink"):
print("SKIP")
- sys.exit()
+ raise SystemExit
# cleanup in case testfile exists
try:
diff --git a/tests/io/resource_stream.py b/tests/io/resource_stream.py
new file mode 100644
index 000000000..37d985bf1
--- /dev/null
+++ b/tests/io/resource_stream.py
@@ -0,0 +1,15 @@
+import uio
+import sys
+
+try:
+ uio.resource_stream
+except AttributeError:
+ print('SKIP')
+ raise SystemExit
+
+buf = uio.resource_stream("data", "file2")
+print(buf.read())
+
+# resource_stream(None, ...) look ups from current dir, hence sys.path[0] hack
+buf = uio.resource_stream(None, sys.path[0] + "/data/file2")
+print(buf.read())
diff --git a/tests/io/resource_stream.py.exp b/tests/io/resource_stream.py.exp
new file mode 100644
index 000000000..75404a347
--- /dev/null
+++ b/tests/io/resource_stream.py.exp
@@ -0,0 +1,2 @@
+1234
+1234
diff --git a/tests/io/write_ext.py b/tests/io/write_ext.py
index 19b616174..5a6eaa35c 100644
--- a/tests/io/write_ext.py
+++ b/tests/io/write_ext.py
@@ -5,9 +5,8 @@ import uio
try:
uio.BytesIO
except AttributeError:
- import sys
print('SKIP')
- sys.exit()
+ raise SystemExit
buf = uio.BytesIO()