Martin v. Löwis | b96e0e5 | 2000-09-19 16:35:39 +0000 | [diff] [blame] | 1 | # Tests StringIO and cStringIO |
| 2 | |
| 3 | import string |
| 4 | |
| 5 | def 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 Drake | 9543833 | 2000-09-28 04:25:33 +0000 | [diff] [blame] | 12 | 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öwis | b96e0e5 | 2000-09-19 16:35:39 +0000 | [diff] [blame] | 35 | # Don't bother testing cStringIO without |
| 36 | import StringIO, cStringIO |
| 37 | do_test(StringIO) |
| 38 | do_test(cStringIO) |