aboutsummaryrefslogtreecommitdiff
path: root/tests/io/bytesio_cow.py
diff options
context:
space:
mode:
authorPaul Sokolovsky2017-06-05 23:54:21 +0300
committerPaul Sokolovsky2017-06-09 17:33:01 +0300
commit07241cd37a732e4219257e6b2fc67a84085b37f6 (patch)
tree7c41bb31dfaffd45e11dd0ed21a52cb145b71542 /tests/io/bytesio_cow.py
parentb24ccfc639416c9427640b5f38e64a1476c1c704 (diff)
py/objstringio: If created from immutable object, follow copy on write policy.
Don't create copy of immutable object's contents until .write() is called on BytesIO.
Diffstat (limited to 'tests/io/bytesio_cow.py')
-rw-r--r--tests/io/bytesio_cow.py20
1 files changed, 20 insertions, 0 deletions
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())