py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Lib / test / test_StringIO.py
blob8d3c85142aa396af01156491b0a5fc77ba9ce9e5
1 # Tests StringIO and cStringIO
3 def do_test(module):
4 s = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+'\n')*5
5 f = module.StringIO(s)
6 print f.read(10)
7 print f.readline()
8 print len(f.readlines(60))
10 f = module.StringIO()
11 f.write('abcdef')
12 f.seek(3)
13 f.write('uvwxyz')
14 f.write('!')
15 print `f.getvalue()`
16 f.close()
18 f = module.StringIO()
19 f.writelines(["a", "b", "c"])
20 f.seek(0)
21 print `f.getvalue()`
22 f.close()
24 f = module.StringIO()
25 f.write(s)
26 f.seek(10)
27 f.truncate()
28 print `f.getvalue()`
29 f.seek(0)
30 f.truncate(5)
31 print `f.getvalue()`
32 f.close()
33 try:
34 f.write("frobnitz")
35 except ValueError, e:
36 print "Caught expected ValueError writing to closed StringIO:"
37 print e
38 else:
39 print "Failed to catch ValueError writing to closed StringIO."
41 import StringIO, cStringIO
42 do_test(StringIO)
43 do_test(cStringIO)