blob: eab8a60688939288ee742ed5ef4f5fcf8215522b [file] [log] [blame]
Guido van Rossum07b78a82001-01-09 21:47:44 +00001from test_support import verbose
2
3class XReader:
Tim Petersd2bf3b72001-01-18 02:22:22 +00004 def __init__(self):
5 self.count = 5
Guido van Rossum07b78a82001-01-09 21:47:44 +00006
Tim Petersd2bf3b72001-01-18 02:22:22 +00007 def readlines(self, sizehint = None):
8 self.count = self.count - 1
9 return map(lambda x: "%d\n" % x, range(self.count))
Guido van Rossum07b78a82001-01-09 21:47:44 +000010
11class Null: pass
12
13import xreadlines
14
15
16lineno = 0
17
18try:
Tim Petersd2bf3b72001-01-18 02:22:22 +000019 xreadlines.xreadlines(Null())[0]
Guido van Rossum07b78a82001-01-09 21:47:44 +000020except AttributeError, detail:
Tim Petersd2bf3b72001-01-18 02:22:22 +000021 print "AttributeError (expected)"
Guido van Rossum07b78a82001-01-09 21:47:44 +000022else:
Tim Petersd2bf3b72001-01-18 02:22:22 +000023 print "Did not throw attribute error"
Guido van Rossum07b78a82001-01-09 21:47:44 +000024
25try:
Tim Petersd2bf3b72001-01-18 02:22:22 +000026 xreadlines.xreadlines(XReader)[0]
Guido van Rossum07b78a82001-01-09 21:47:44 +000027except TypeError, detail:
Tim Petersd2bf3b72001-01-18 02:22:22 +000028 print "TypeError (expected)"
Guido van Rossum07b78a82001-01-09 21:47:44 +000029else:
Tim Petersd2bf3b72001-01-18 02:22:22 +000030 print "Did not throw type error"
Guido van Rossum07b78a82001-01-09 21:47:44 +000031
32try:
Tim Petersd2bf3b72001-01-18 02:22:22 +000033 xreadlines.xreadlines(XReader())[1]
Guido van Rossum07b78a82001-01-09 21:47:44 +000034except RuntimeError, detail:
Tim Petersd2bf3b72001-01-18 02:22:22 +000035 print "RuntimeError (expected):", detail
Guido van Rossum07b78a82001-01-09 21:47:44 +000036else:
Tim Petersd2bf3b72001-01-18 02:22:22 +000037 print "Did not throw runtime error"
Guido van Rossum07b78a82001-01-09 21:47:44 +000038
39xresult = ['0\n', '1\n', '2\n', '3\n', '0\n', '1\n', '2\n', '0\n', '1\n', '0\n']
40for line in xreadlines.xreadlines(XReader()):
Tim Petersd2bf3b72001-01-18 02:22:22 +000041 if line != xresult[lineno]:
42 print "line %d differs" % lineno
43 lineno += 1