def test_posix_printengine_tty(self):
"""Test POSIX print engine tty mode."""
sio = six.StringIO()
def __drain(masterf):
"""Drain data from masterf and discard until eof."""
while True:
chunksz = 1024
termdata = masterf.read(chunksz)
if len(termdata) < chunksz:
# assume we hit EOF
break
print(termdata, file=sio)
#
# - Allocate a pty
# - Create a thread to drain off the master side; without
# this, the slave side will block when trying to write.
# - Connect the printengine to the slave side
# - Set it running
#
(master, slave) = pty.openpty()
slavef = os.fdopen(slave, "w")
masterf = os.fdopen(master, "r")
t = threading.Thread(target=__drain, args=(masterf,))
t.start()
printengine.test_posix_printengine(slavef, True)
slavef.close()
t.join()
masterf.close()
self.assertTrue(len(sio.getvalue()) > 0)
评论列表
文章目录