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: termdata = masterf.read(1024) if len(termdata) < 1024: if len(termdata) > 0: print (termdata, file=sio) 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)
def test_posix_printengine_tty(self): """Test POSIX print engine tty mode.""" sio = StringIO.StringIO() def __drain(masterf): """Drain data from masterf and discard until eof.""" while True: termdata = masterf.read(1024) if len(termdata) == 0: break print >> sio, termdata # # - 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.assert_(len(sio.getvalue()) > 0)
def test_posix_printengine_notty(self): """Smoke test POSIX print engine non-tty mode.""" sio = six.StringIO() printengine.test_posix_printengine(sio, False) self.assertTrue(len(sio.getvalue()) > 0)
print("must specify one or more of -t, -T or -l", file=sys.stderr) sys.exit(2) if len(argv) == 1: output_file = open(argv[0], "w") elif len(argv) > 1: print("too many arguments", file=sys.stderr) sys.exit(2) else: output_file = sys.stdout try: if test_ttymode: print("---test_ttymode---", file=output_file) print(("-" * 60), file=output_file) printengine.test_posix_printengine(output_file, True) if test_nottymode: print("---test_nottymode---", file=output_file) print(("-" * 60), file=output_file) printengine.test_posix_printengine(output_file, False) if test_logging: print("---test_logging---", file=output_file) print(("-" * 60), output_file) printengine.test_logging_printengine(output_file) except printengine.PrintEngineException as e: print(e, file=sys.stderr) sys.exit(1) except: traceback.print_exc() sys.exit(99) sys.exit(0)
"must specify one or more of -t, -T or -l" sys.exit(2) if len(argv) == 1: output_file = open(argv[0], "w") elif len(argv) > 1: print >> sys.stderr, "too many arguments" sys.exit(2) else: output_file = sys.stdout try: if test_ttymode: print >> output_file, "---test_ttymode---" print >> output_file, ("-" * 60) printengine.test_posix_printengine(output_file, True) if test_nottymode: print >> output_file, "---test_nottymode---" print >> output_file, ("-" * 60) printengine.test_posix_printengine(output_file, False) if test_logging: print >> output_file, "---test_logging---" print >> output_file, ("-" * 60) printengine.test_logging_printengine(output_file) except printengine.PrintEngineException, e: print >> sys.stderr, e sys.exit(1) except: traceback.print_exc() sys.exit(99) sys.exit(0)
def test_posix_printengine_notty(self): """Smoke test POSIX print engine non-tty mode.""" sio = StringIO.StringIO() printengine.test_posix_printengine(sio, False) self.assert_(len(sio.getvalue()) > 0)