File: test_wait.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 (32 lines) | stat: -rw-r--r-- 1,275 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
""" Test cases for PtyProcess.wait method. """
import time
import unittest
from ptyprocess import PtyProcess


class TestWaitAfterTermination(unittest.TestCase):
    """Various test cases for PtyProcess.wait()"""

    def test_wait_true_shortproc(self):
        """Ensure correct (True) wait status for short-lived processes."""
        child = PtyProcess.spawn(['true'])
        # Wait so we're reasonable sure /bin/true has terminated
        time.sleep(0.2)
        self.assertEqual(child.wait(), 0)

    def test_wait_false_shortproc(self):
        """Ensure correct (False) wait status for short-lived processes."""
        child = PtyProcess.spawn(['false'])
        # Wait so we're reasonable sure /bin/false has terminated
        time.sleep(0.2)
        self.assertNotEqual(child.wait(), 0)

    def test_wait_twice_longproc(self):
        """Ensure correct wait status when called twice."""
        # previous versions of ptyprocess raises PtyProcessError when
        # wait was called more than once with "Cannot wait for dead child
        # process.".  No longer true since v0.5.
        child = PtyProcess.spawn(['sleep', '1'])
        # this call to wait() will block for 1s
        for count in range(2):
            self.assertEqual(child.wait(), 0, count)