|
| 1 | +""" |
| 2 | +Unit test of trepan.api |
| 3 | +""" |
| 4 | + |
| 5 | +import sys |
| 6 | + |
| 7 | +import tracer |
| 8 | + |
| 9 | +from trepan.api import run_call, run_eval |
| 10 | +from trepan.inout.stringarray import StringArrayInput, StringArrayOutput |
| 11 | +from trepan.lib.default import DEBUGGER_SETTINGS |
| 12 | + |
| 13 | + |
| 14 | +def plus5(n: int) -> int: |
| 15 | + return n + 5 |
| 16 | + |
| 17 | + |
| 18 | +def test_run_xxx(): |
| 19 | + """ |
| 20 | + test run_eval() and run_call() |
| 21 | + """ |
| 22 | + settings = dict(DEBUGGER_SETTINGS) |
| 23 | + settings.update({"trace": True, "printset": tracer.ALL_EVENTS}) |
| 24 | + debugger_input = StringArrayInput() |
| 25 | + debugger_output = StringArrayOutput() |
| 26 | + debug_opts = { |
| 27 | + "step_ignore": -1, |
| 28 | + "settings": settings, |
| 29 | + "input": debugger_input, |
| 30 | + "output": debugger_output, |
| 31 | + } |
| 32 | + print('Issuing: run_eval("1+2")') |
| 33 | + print(run_eval("1+2", debug_opts=debug_opts)) |
| 34 | + print(debugger_output.output) |
| 35 | + start_lineno = "1" if sys.version_info[:2] < (3, 10) else "0" |
| 36 | + assert debugger_output.output[0:3] == [ |
| 37 | + "call - <string>:%s" % start_lineno, |
| 38 | + "line - <string>:1", |
| 39 | + "return - <string>:1, 3 ", |
| 40 | + ] |
| 41 | + debugger_input = StringArrayInput([""]) |
| 42 | + debugger_output = StringArrayOutput() |
| 43 | + debug_opts = { |
| 44 | + "step_ignore": -1, |
| 45 | + "settings": settings, |
| 46 | + "input": debugger_input, |
| 47 | + "output": debugger_output, |
| 48 | + } |
| 49 | + print('Issuing: run_call(foo, 3")') |
| 50 | + x = run_call(plus5, 3, debug_opts=debug_opts) |
| 51 | + assert x == 8 |
| 52 | + call_lineno = "12" |
| 53 | + for i, (prefix, suffix) in enumerate( |
| 54 | + ( |
| 55 | + ("call - ", "test/unit/test_api.py:%s" % call_lineno), |
| 56 | + ("line - ", "test/unit/test_api.py:13"), |
| 57 | + ("return - ", "test/unit/test_api.py:13, 8 "), |
| 58 | + ) |
| 59 | + ): |
| 60 | + assert debugger_output.output[i].startswith(prefix), debugger_output.output[i] |
| 61 | + if not debugger_output.output[i].endswith(suffix): |
| 62 | + from trepan.api import debug |
| 63 | + |
| 64 | + debug() |
| 65 | + assert debugger_output.output[i].endswith(suffix), debugger_output.output[i] |
0 commit comments