mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Test for xreadline.
This commit is contained in:
parent
ea3375d96b
commit
07b78a8778
2 changed files with 46 additions and 0 deletions
4
Lib/test/output/test_xreadline
Normal file
4
Lib/test/output/test_xreadline
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
test_xrl
|
||||||
|
AttributeError
|
||||||
|
TypeError
|
||||||
|
RuntimeError xreadlines object accessed out of order
|
||||||
42
Lib/test/test_xreadline.py
Normal file
42
Lib/test/test_xreadline.py
Normal file
|
|
@ -0,0 +1,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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue