Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_StringIO.py @ 15156:becd8a121464 legacy-trunk
Jack Jansen reported that the regression test failed on the Mac where
string.letters was much more than expected.
Solution: explicit is better than implicit; don't rely on
string.letters.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 11 Oct 2000 21:34:53 +0000 |
| parents | 3a04bebb666a |
| children | ab1f90dd502f |
| 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 def do_test(module): |
|
15156
becd8a121464
Jack Jansen reported that the regression test failed on the Mac where
Guido van Rossum <guido@python.org>
parents:
15058
diff
changeset
|
4 s = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+'\n')*5 |
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 f = module.StringIO(s) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
6 print f.read(10) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
7 print f.readline() |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
8 print len(f.readlines(60)) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 |
|
14905
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 f.truncate() |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
14 print `f.getvalue()` |
|
15058
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
15 f.seek(0) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
16 f.truncate(5) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
17 print `f.getvalue()` |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
18 f.close() |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
19 try: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
20 f.write("frobnitz") |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
21 except ValueError, e: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
22 print "Caught expected ValueError writing to closed StringIO:" |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
23 print e |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
24 else: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
25 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
|
26 |
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
27 # 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
|
28 import StringIO, cStringIO |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
29 do_test(StringIO) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
30 do_test(cStringIO) |
