Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: b3570e83e5da8bc51d7167bd55bb9aa42a033032 authored by cvs2svn on 02 March 2001, 19:48:06 UTC
This commit was manufactured by cvs2svn to create tag 'r21b1'.
Tip revision: b3570e8
test_xreadline.py
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 (expected)"
else:
    print "Did not throw attribute error"

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

try:
    xreadlines.xreadlines(XReader())[1]
except RuntimeError, detail:
    print "RuntimeError (expected):", 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 += 1
back to top