Merge pull request #1597 from palaviv/io-improve · RustPython/RustPython@c3330d3 · GitHub
Skip to content

Commit c3330d3

Browse files
authored
Merge pull request #1597 from palaviv/io-improve
Add readline,tell to BytesIO and StringIO
2 parents 60ebba2 + 7b83e8a commit c3330d3

3 files changed

Lines changed: 92 additions & 6 deletions

File tree

tests/snippets/stdlib_io_bytesio.py

Lines changed: 30 additions & 0 deletions

tests/snippets/stdlib_io_stringio.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def test_01():
1010
f = StringIO()
1111
f.write(string)
1212

13+
assert f.tell() == len(string)
1314
assert f.getvalue() == string
1415

1516
def test_02():
@@ -46,11 +47,26 @@ def test_04():
4647
f = StringIO(string)
4748

4849
assert f.read(4) == 'Test'
50+
assert f.tell() == 4
4951
assert f.seek(0) == 0
5052
assert f.read(4) == 'Test'
5153

54+
def test_05():
55+
"""
56+
Tests readline
57+
"""
58+
string = 'Test String 6\nnew line is here\nfinished'
59+
60+
f = StringIO(string)
61+
62+
assert f.readline() == 'Test String 6\n'
63+
assert f.readline() == 'new line is here\n'
64+
assert f.readline() == 'finished'
65+
assert f.readline() == ''
66+
5267
if __name__ == "__main__":
5368
test_01()
5469
test_02()
5570
test_03()
5671
test_04()
72+
test_05()

vm/src/stdlib/io.rs

Lines changed: 46 additions & 6 deletions

0 commit comments

Comments
 (0)