| 1 | import time |
| 2 | import unittest |
| 3 | from ptyprocess.ptyprocess import _is_solaris |
| 4 | from ptyprocess import PtyProcess |
| 5 | |
| 6 | class PtyEchoTestCase(unittest.TestCase): |
| 7 | |
| 8 | def _read_until_eof(self, proc): |
| 9 | """Read away all output on ``proc`` until EOF.""" |
| 10 | while True: |
| 11 | try: |
| 12 | proc.read() |
| 13 | except EOFError: |
| 14 | return |
| 15 | |
| 16 | @unittest.skipIf(_is_solaris, "waitnoecho cannot be called on this platform.") |
| 17 | def test_waitnoecho_forever(self): |
| 18 | """Ensure waitnoecho() with no timeout will return when echo=False.""" |
| 19 | cat = PtyProcess.spawn(['cat'], echo=False) |
| 20 | assert cat.waitnoecho() == True |
| 21 | assert cat.echo == False |
| 22 | assert cat.getecho() == False |
| 23 | cat.sendeof() |
| 24 | self._read_until_eof(cat) |
| 25 | assert cat.wait() == 0 |
| 26 | |
| 27 | @unittest.skipIf(_is_solaris, "waitnoecho cannot be called on this platform.") |
| 28 | def test_waitnoecho_timeout(self): |
| 29 | """Ensure waitnoecho() with timeout will return when using stty to unset echo.""" |
| 30 | cat = PtyProcess.spawn(['cat'], echo=True) |
| 31 | assert cat.waitnoecho(timeout=1) == False |
| 32 | assert cat.echo == True |
| 33 | assert cat.getecho() == True |
| 34 | cat.sendeof() |
| 35 | self._read_until_eof(cat) |
| 36 | assert cat.wait() == 0 |