Debian Codegraph @

tests/test_wait.py

raw symbols SCIP
1 """ Test cases for PtyProcess.wait method. """
2 import time
3 import unittest
4 from ptyprocess import PtyProcess
5
6
7 class TestWaitAfterTermination(unittest.TestCase):
8 """Various test cases for PtyProcess.wait()"""
9
10 def test_wait_true_shortproc(self):
11 """Ensure correct (True) wait status for short-lived processes."""
12 child = PtyProcess.spawn(['true'])
13 # Wait so we're reasonable sure /bin/true has terminated
14 time.sleep(0.2)
15 self.assertEqual(child.wait(), 0)
16
17 def test_wait_false_shortproc(self):
18 """Ensure correct (False) wait status for short-lived processes."""
19 child = PtyProcess.spawn(['false'])
20 # Wait so we're reasonable sure /bin/false has terminated
21 time.sleep(0.2)
22 self.assertNotEqual(child.wait(), 0)
23
24 def test_wait_twice_longproc(self):
25 """Ensure correct wait status when called twice."""
26 # previous versions of ptyprocess raises PtyProcessError when
27 # wait was called more than once with "Cannot wait for dead child
28 # process.". No longer true since v0.5.
29 child = PtyProcess.spawn(['sleep', '1'])
30 # this call to wait() will block for 1s
31 for count in range(2):
32 self.assertEqual(child.wait(), 0, count)