Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_StringIO.py @ 16413:8819867f14ef legacy-trunk
Patch derived from Trent's 101162: a Python/C API testing framework.
STILL NEEDS UNIX BUILD CHANGES.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Fri, 02 Feb 2001 05:57:15 +0000 |
| parents | ab1f90dd502f |
| children | 60a2e99c863b |
| 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() |
|
ab1f90dd502f
Added a test for the StringIO write() error I just fixed.
Guido van Rossum <guido@python.org>
parents:
15156
diff
changeset
|
17 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
|
18 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
|
19 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
|
20 f.truncate() |
|
45967ff1b6dc
Added some tests for the truncate() method; one is commented out because
Fred Drake <fdrake@acm.org>
parents:
14688
diff
changeset
|
21 print `f.getvalue()` |
|
15058
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
22 f.seek(0) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
23 f.truncate(5) |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
24 print `f.getvalue()` |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
25 f.close() |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
26 try: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
27 f.write("frobnitz") |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
28 except ValueError, e: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
29 print "Caught expected ValueError writing to closed StringIO:" |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
30 print e |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
31 else: |
|
3a04bebb666a
Uncommented tests that failed for cStringIO,
Jim Fulton <jim@zope.com>
parents:
14905
diff
changeset
|
32 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
|
33 |
|
14688
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
34 # 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
|
35 import StringIO, cStringIO |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
36 do_test(StringIO) |
|
d6ffb6d7fe8a
New test cases for the StringIO module
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
37 do_test(cStringIO) |
