File: test_echo.py

package info (click to toggle)
ptyprocess 0.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: python: 923; makefile: 146; sh: 8
file content (36 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import unittest
from ptyprocess.ptyprocess import _is_solaris
from ptyprocess import PtyProcess

class PtyEchoTestCase(unittest.TestCase):

    def _read_until_eof(self, proc):
        """Read away all output on ``proc`` until EOF."""
        while True:
            try:
                proc.read()
            except EOFError:
                return

    @unittest.skipIf(_is_solaris, "waitnoecho cannot be called on this platform.")
    def test_waitnoecho_forever(self):
        """Ensure waitnoecho() with no timeout will return when echo=False."""
        cat = PtyProcess.spawn(['cat'], echo=False)
        assert cat.waitnoecho() == True
        assert cat.echo == False
        assert cat.getecho() == False
        cat.sendeof()
        self._read_until_eof(cat)
        assert cat.wait() == 0

    @unittest.skipIf(_is_solaris, "waitnoecho cannot be called on this platform.")
    def test_waitnoecho_timeout(self):
        """Ensure waitnoecho() with timeout will return when using stty to unset echo."""
        cat = PtyProcess.spawn(['cat'], echo=True)
        assert cat.waitnoecho(timeout=1) == False
        assert cat.echo == True
        assert cat.getecho() == True
        cat.sendeof()
        self._read_until_eof(cat)
        assert cat.wait() == 0