Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07b78a8

Browse files
committed
Test for xreadline.
1 parent ea3375d commit 07b78a8

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lib/test/output/test_xreadline

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_xrl
2+
AttributeError
3+
TypeError
4+
RuntimeError xreadlines object accessed out of order

Lib/test/test_xreadline.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from test_support import verbose
2+
3+
class XReader:
4+
def __init__(self):
5+
self.count = 5
6+
7+
def readlines(self, sizehint = None):
8+
self.count = self.count - 1
9+
return map(lambda x: "%d\n" % x, range(self.count))
10+
11+
class Null: pass
12+
13+
import xreadlines
14+
15+
16+
lineno = 0
17+
18+
try:
19+
xreadlines.xreadlines(Null())[0]
20+
except AttributeError, detail:
21+
print "AttributeError"
22+
else:
23+
print "Did not throw attribute error"
24+
25+
try:
26+
xreadlines.xreadlines(XReader)[0]
27+
except TypeError, detail:
28+
print "TypeError"
29+
else:
30+
print "Did not throw type error"
31+
32+
try:
33+
xreadlines.xreadlines(XReader())[1]
34+
except RuntimeError, detail:
35+
print "RuntimeError", detail
36+
else:
37+
print "Did not throw runtime error"
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()):
41+
if line != xresult[lineno]: print "line %d differs" % lineno
42+
lineno = lineno + 1

0 commit comments

Comments
 (0)