t_printengine.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号