view Lib/test/test_StringIO.py @ 17322:bd110eadc19a legacy-trunk

One-liner critical fix from Jim Fulton: Eric's string-method crusade got the order backwards in a line (for .find()).
author Tim Peters <tim.peters@gmail.com>
date Thu, 05 Apr 2001 22:26:23 +0000
parents 60a2e99c863b
children 6378cb117b73
line wrap: on
line source

# Tests StringIO and cStringIO

def do_test(module):
    s = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+'\n')*5
    f = module.StringIO(s)
    print f.read(10)
    print f.readline()
    print len(f.readlines(60))

    f = module.StringIO()
    f.write('abcdef')
    f.seek(3)
    f.write('uvwxyz')
    f.write('!')
    print `f.getvalue()`
    f.close()

    f = module.StringIO()
    f.writelines(["a", "b", "c"])
    f.seek(0)
    print `f.getvalue()`
    f.close()

    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."

import StringIO, cStringIO
do_test(StringIO)
do_test(cStringIO)