cpython/Lib/test/test_StringIO.py
Jim Fulton d1229f5651 Uncommented tests that failed for cStringIO,
Added missing clode to make the clode test test a close. ;)
2000-10-06 19:21:32 +00:00

33 lines
709 B
Python

# Tests StringIO and cStringIO
import string
def do_test(module):
s = (string.letters+'\n')*5
f = module.StringIO(s)
print f.read(10)
print f.readline()
print len(f.readlines(60))
f = module.StringIO()
f.write(s)
f.seek(10)
f.truncate()
print `f.getvalue()`
f.seek(0)
f.truncate(5)
print `f.getvalue()`
f.close()
try:
f.write("frobnitz")
except ValueError, e:
print "Caught expected ValueError writing to closed StringIO:"
print e
else:
print "Failed to catch ValueError writing to closed StringIO."
# Don't bother testing cStringIO without
import StringIO, cStringIO
do_test(StringIO)
do_test(cStringIO)