blob: 2d9f2c1ded8758b140bb09ab1a8ca2ac85041ea5 [file] [log] [blame]
Martin v. Löwisb96e0e52000-09-19 16:35:39 +00001# Tests StringIO and cStringIO
2
3import string
4
5def do_test(module):
6 s = (string.letters+'\n')*5
7 f = module.StringIO(s)
8 print f.read(10)
9 print f.readline()
10 print len(f.readlines(60))
11
Fred Drake95438332000-09-28 04:25:33 +000012 f = module.StringIO()
13 f.write(s)
14 f.seek(10)
15 f.truncate()
16 print `f.getvalue()`
17 # This test fails for cStringIO; reported as SourceForge bug #115531;
18 # please uncomment this test when that bug is fixed.
19 # http://sourceforge.net/bugs/?func=detailbug&bug_id=115531&group_id=5470
20## f.seek(0)
21## f.truncate(5)
22## print `f.getvalue()`
23
24 # This test fails for cStringIO; reported as SourceForge bug #115530;
25 # please uncomment this test when that bug is fixed.
26 # http://sourceforge.net/bugs/?func=detailbug&bug_id=115530&group_id=5470
27## try:
28## f.write("frobnitz")
29## except ValueError, e:
30## print "Caught expected ValueError writing to closed StringIO:"
31## print e
32## else:
33## print "Failed to catch ValueError writing to closed StringIO."
34
Martin v. Löwisb96e0e52000-09-19 16:35:39 +000035# Don't bother testing cStringIO without
36import StringIO, cStringIO
37do_test(StringIO)
38do_test(cStringIO)