OLD | NEW |
(Empty) | |
| 1 import io |
| 2 import sys |
| 3 import unittest |
| 4 try: |
| 5 import builtins |
| 6 except ImportError: |
| 7 import __builtin__ as builtins |
| 8 |
| 9 PY3 = (sys.version_info[0] >= 3) |
| 10 input_name = 'input' if PY3 else 'raw_input' |
| 11 |
| 12 from pexpect import FSM |
| 13 |
| 14 class FSMTestCase(unittest.TestCase): |
| 15 def test_run_fsm(self): |
| 16 def _input(prompt): |
| 17 return "167 3 2 2 * * * 1 - =" |
| 18 orig_input = getattr(builtins, input_name) |
| 19 orig_stdout = sys.stdout |
| 20 setattr(builtins, input_name, _input) |
| 21 sys.stdout = sio = (io.StringIO if PY3 else io.BytesIO)() |
| 22 |
| 23 try: |
| 24 FSM.main() |
| 25 finally: |
| 26 setattr(builtins, input_name, orig_input) |
| 27 sys.stdout = orig_stdout |
| 28 |
| 29 printed = sio.getvalue() |
| 30 assert '2003' in printed, printed |
| 31 |
| 32 |
| 33 if __name__ == '__main__': |
| 34 unittest.main() |
OLD | NEW |