| 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 |
|
| 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 |
|
| 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 |
|
| 27 |
|
| 28 |
|
| 29 |
child = PtyProcess.spawn(['sleep', '1']) |
| 30 |
|
| 31 |
for count in range(2): |
| 32 |
self.assertEqual(child.wait(), 0, count) |