Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_StringIO.py @ 15058:3a04bebb666a legacy-trunk
Uncommented tests that failed for cStringIO,
Added missing clode to make the clode test test a close. ;)
| author | Jim Fulton <jim@zope.com> |
|---|---|
| date | Fri, 06 Oct 2000 19:21:32 +0000 |
| parents | 45967ff1b6dc |
| children | becd8a121464 |
| rev | line source |
|---|---|
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1 # Tests StringIO and cStringIO |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
2 |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
3 import string |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 def do_test(module): |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
6 s = (string.letters+'\n')*5 |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
7 f = module.StringIO(s) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
8 print f.read(10) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 print f.readline() |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
10 print len(f.readlines(60)) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
11 |
|
14905
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
12 f = module.StringIO() |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
13 f.write(s) |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
14 f.seek(10) |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
15 f.truncate() |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
16 print `f.getvalue()` |
|
15058
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
17 f.seek(0) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
18 f.truncate(5) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
19 print `f.getvalue()` |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
20 f.close() |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
21 try: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
22 f.write("frobnitz") |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
23 except ValueError, e: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
24 print "Caught expected ValueError writing to closed StringIO:" |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
25 print e |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
26 else: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
27 print "Failed to catch ValueError writing to closed StringIO." |
|
14905
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
28 |
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
29 # Don't bother testing cStringIO without |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
30 import StringIO, cStringIO |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
31 do_test(StringIO) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
32 do_test(cStringIO) |
