Mercurial > cpython-lru_cache-weakref
annotate 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 |
| 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() |
|
15175
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
11 f.write('abcdef') |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
12 f.seek(3) |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
13 f.write('uvwxyz') |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
14 f.write('!') |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
15 print `f.getvalue()` |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
16 f.close() |
|
16546
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
17 |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
18 f = module.StringIO() |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
19 f.writelines(["a", "b", "c"]) |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
20 f.seek(0) |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
21 print `f.getvalue()` |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
22 f.close() |
|
60a2e99c863b
In O_writelines: Replace use of string.joinfields with "".join.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15175
diff
changeset
|
23 |
|
15175
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
24 f = module.StringIO() |
|
14905
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
25 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
|
26 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
|
27 f.truncate() |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
28 print `f.getvalue()` |
|
15058
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
29 f.seek(0) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
30 f.truncate(5) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
31 print `f.getvalue()` |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
32 f.close() |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
33 try: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
34 f.write("frobnitz") |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
35 except ValueError, e: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
36 print "Caught expected ValueError writing to closed StringIO:" |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
37 print e |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
38 else: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
39 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
|
40 |
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
41 import StringIO, cStringIO |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 do_test(StringIO) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 do_test(cStringIO) |
