def test_iter (self):
'''See the note in test_readlines() for an explaination as to why
I allow line3 and line4 to return multiple patterns.
Basically, this is done to handle a valid condition on slow systems.
'''
child = pexpect.spawn('cat')
child.sendline ("abc")
time.sleep(0.5)
child.sendline ("123")
time.sleep(0.5)
child.sendeof()
# Don't use ''.join() because we want to test the ITERATOR.
page = b''
for line in child:
page += line
page = page.replace(_CAT_EOF, b'')
# This is just a really bad test all together, we should write our
# own 'cat' utility that only writes to stdout after EOF is recv,
# this must take into consideration all possible platform impl.'s
# of `cat', and their related terminal and line-buffer handling
assert (page == b'abc\r\nabc\r\n123\r\n123\r\n' or
page == b'abc\r\n123\r\nabc\r\n123\r\n' or
page == b'abc\r\n123abc\r\n\r\n123\r\n') , \
"iterator did not work. page=%r" % (page,)
评论列表
文章目录