aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2020-02-27 15:15:56 +0000
committerRonan Lamy <ronan.lamy@gmail.com>2020-02-27 15:15:56 +0000
commite9c904408e8e8dbdd15ce6bd99ca794c090b8d8d (patch)
tree2ebdd246b5e9eeb4ff159aec2b25b45cd16a1a2e /extra_tests
parentmerge default into branch (diff)
downloadpypy-e9c904408e8e8dbdd15ce6bd99ca794c090b8d8d.tar.gz
pypy-e9c904408e8e8dbdd15ce6bd99ca794c090b8d8d.tar.bz2
pypy-e9c904408e8e8dbdd15ce6bd99ca794c090b8d8d.zip
Backport changes from branch py3-StringIO-perf
Diffstat (limited to 'extra_tests')
-rw-r--r--extra_tests/test_stringio.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/extra_tests/test_stringio.py b/extra_tests/test_stringio.py
new file mode 100644
index 0000000000..040e91a4a2
--- /dev/null
+++ b/extra_tests/test_stringio.py
@@ -0,0 +1,54 @@
+from hypothesis import given, strategies as st
+
+from io import StringIO
+from os import linesep
+
+LINE_ENDINGS = [u'\n', u'\r', u'\r\n']
+
+@given(txt=st.text(), newline=st.sampled_from(['', '\n']))
+def test_simple(txt, newline):
+ sio = StringIO(txt, newline=newline)
+ assert sio.getvalue() == txt
+
+@given(values=st.lists(
+ st.tuples(
+ st.text(st.characters(blacklist_characters='\r\n'), min_size=1),
+ st.sampled_from(LINE_ENDINGS))))
+def test_universal(values):
+ output_lines = [line + linesep for line, ending in values]
+ output = u''.join(output_lines)
+
+ input = u''.join(line + ending for line, ending in values)
+ sio = StringIO(input, newline=None)
+ sio.seek(0)
+ assert list(sio) == output_lines
+ assert sio.getvalue() == output
+
+ sio2 = StringIO(newline=None)
+ for line, ending in values:
+ sio2.write(line)
+ sio2.write(ending)
+ sio2.seek(0)
+ assert list(sio2) == output_lines
+ assert sio2.getvalue() == output
+
+@given(
+ lines=st.lists(st.text(st.characters(blacklist_characters='\r\n'))),
+ newline=st.sampled_from(['\r', '\r\n']))
+def test_crlf(lines, newline):
+ output_lines = [line + newline for line in lines]
+ output = u''.join(output_lines)
+
+ input = u''.join(line + '\n' for line in lines)
+ sio = StringIO(input, newline=newline)
+ sio.seek(0)
+ assert list(sio) == output_lines
+ assert sio.getvalue() == output
+
+ sio2 = StringIO(newline=newline)
+ for line in lines:
+ sio2.write(line)
+ sio2.write(u'\n')
+ sio2.seek(0)
+ assert list(sio2) == output_lines
+ assert sio2.getvalue() == ''.join(output_lines)