test_xreadline.py
来自「mallet是自然语言处理、机器学习领域的一个开源项目。」· Python 代码 · 共 44 行
PY
44 行
from test_support import verboseclass 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: passimport xreadlineslineno = 0try: 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):", detailelse: 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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?