Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 1 | from test_support import verbose |
| 2 | |
| 3 | class XReader: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 4 | def __init__(self): |
| 5 | self.count = 5 |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 6 | |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 7 | def readlines(self, sizehint = None): |
| 8 | self.count = self.count - 1 |
| 9 | return map(lambda x: "%d\n" % x, range(self.count)) |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 10 | |
| 11 | class Null: pass |
| 12 | |
| 13 | import xreadlines |
| 14 | |
| 15 | |
| 16 | lineno = 0 |
| 17 | |
| 18 | try: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 19 | xreadlines.xreadlines(Null())[0] |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 20 | except AttributeError, detail: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 21 | print "AttributeError (expected)" |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 22 | else: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 23 | print "Did not throw attribute error" |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 24 | |
| 25 | try: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 26 | xreadlines.xreadlines(XReader)[0] |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 27 | except TypeError, detail: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 28 | print "TypeError (expected)" |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 29 | else: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 30 | print "Did not throw type error" |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 31 | |
| 32 | try: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 33 | xreadlines.xreadlines(XReader())[1] |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 34 | except RuntimeError, detail: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 35 | print "RuntimeError (expected):", detail |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 36 | else: |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 37 | print "Did not throw runtime error" |
Guido van Rossum | 07b78a8 | 2001-01-09 21:47:44 +0000 | [diff] [blame] | 38 | |
| 39 | xresult = ['0\n', '1\n', '2\n', '3\n', '0\n', '1\n', '2\n', '0\n', '1\n', '0\n'] |
| 40 | for line in xreadlines.xreadlines(XReader()): |
Tim Peters | d2bf3b7 | 2001-01-18 02:22:22 +0000 | [diff] [blame] | 41 | if line != xresult[lineno]: |
| 42 | print "line %d differs" % lineno |
| 43 | lineno += 1 |