summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_xreadline.py
blob: 84f7ba42b08f7267dd6416de4f26f8b78aef5d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from test_support import verbose

class XReader:
	def __init__(self):
		self.count = 5

	def readlines(self, sizehint = None):
		self.count = self.count - 1
		return map(lambda x: "%d\n" % x, range(self.count))

class Null: pass

import xreadlines


lineno = 0

try:
	xreadlines.xreadlines(Null())[0]
except AttributeError, detail:
	print "AttributeError"
else:
	print "Did not throw attribute error"

try:
	xreadlines.xreadlines(XReader)[0]
except TypeError, detail:
	print "TypeError"
else:
	print "Did not throw type error"

try:
	xreadlines.xreadlines(XReader())[1]
except RuntimeError, detail:
	print "RuntimeError", detail
else:
	print "Did not throw runtime error"

xresult = ['0\n', '1\n', '2\n', '3\n', '0\n', '1\n', '2\n', '0\n', '1\n', '0\n']
for line in xreadlines.xreadlines(XReader()):
	if line != xresult[lineno]: print "line %d differs" % lineno
	lineno = lineno + 1