forked from pexpect/pexpect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_FSM.py
34 lines (27 loc) · 856 Bytes
/
test_FSM.py
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
import io
import sys
import unittest
try:
import builtins
except ImportError:
import __builtin__ as builtins
PY3 = (sys.version_info[0] >= 3)
input_name = 'input' if PY3 else 'raw_input'
from pexpect import FSM
class FSMTestCase(unittest.TestCase):
def test_run_fsm(self):
def _input(prompt):
return "167 3 2 2 * * * 1 - ="
orig_input = getattr(builtins, input_name)
orig_stdout = sys.stdout
setattr(builtins, input_name, _input)
sys.stdout = sio = (io.StringIO if PY3 else io.BytesIO)()
try:
FSM.main()
finally:
setattr(builtins, input_name, orig_input)
sys.stdout = orig_stdout
printed = sio.getvalue()
assert '2003' in printed, printed
if __name__ == '__main__':
unittest.main()