Refactor test_start_stop to use the new test API.

This commit is contained in:
Pavel Minaev 2019-09-27 15:54:58 -07:00 committed by Pavel Minaev
parent 8e6182049b
commit 74a85855ad

View file

@ -17,11 +17,9 @@ from tests.patterns import some
def has_waited(session):
lines = session.captured_output.stdout_lines()
result = any(
return any(
s == some.bytes.matching(br"Press .* to continue . . .\s*") for s in lines
)
# log.info("!!! {1} {0!r}", lines, result)
return result
def wait_and_press_key(session):
@ -29,14 +27,17 @@ def wait_and_press_key(session):
while not has_waited(session):
time.sleep(0.1)
log.info("Simulating keypress.")
session.process.stdin.write(b" \r\n")
session.debuggee.stdin.write(b" \r\n")
@pytest.mark.skipif(
sys.version_info < (3, 0) and platform.system() == "Windows",
reason="On Windows + Python 2, unable to send key strokes to test.",
)
def test_wait_on_normal_exit_enabled(pyfile, run_as):
@pytest.mark.parametrize(
"run", [runners.launch["integratedTerminal"], runners.launch["externalTerminal"]]
)
def test_wait_on_normal_exit_enabled(pyfile, target, run):
@pyfile
def code_to_debug():
from debug_me import ptvsd
@ -44,9 +45,11 @@ def test_wait_on_normal_exit_enabled(pyfile, run_as):
ptvsd.break_into_debugger()
print() # line on which it'll actually break
with debug.Session(runners.launch) as session:
session.configure(run_as, code_to_debug, waitOnNormalExit=True)
session.start_debugging()
with debug.Session() as session:
session.config["waitOnNormalExit"] = True
with run(session, target(code_to_debug)):
pass
session.wait_for_stop()
session.request_continue()
@ -58,7 +61,10 @@ def test_wait_on_normal_exit_enabled(pyfile, run_as):
sys.version_info < (3, 0) and platform.system() == "Windows",
reason="On Windows + Python 2, unable to send key strokes to test.",
)
def test_wait_on_abnormal_exit_enabled(pyfile, run_as):
@pytest.mark.parametrize(
"run", [runners.launch["integratedTerminal"], runners.launch["externalTerminal"]]
)
def test_wait_on_abnormal_exit_enabled(pyfile, target, run):
@pyfile
def code_to_debug():
from debug_me import ptvsd
@ -68,10 +74,12 @@ def test_wait_on_abnormal_exit_enabled(pyfile, run_as):
print() # line on which it'll actually break
sys.exit(42)
with debug.Session(runners.launch) as session:
with debug.Session() as session:
session.expected_exit_code = 42
session.configure(run_as, code_to_debug, waitOnAbnormalExit=True)
session.start_debugging()
session.config["waitOnAbnormalExit"] = True
with run(session, target(code_to_debug)):
pass
session.wait_for_stop()
session.request_continue()
@ -79,7 +87,10 @@ def test_wait_on_abnormal_exit_enabled(pyfile, run_as):
wait_and_press_key(session)
def test_exit_normally_with_wait_on_abnormal_exit_enabled(pyfile, run_as):
@pytest.mark.parametrize(
"run", [runners.launch["integratedTerminal"], runners.launch["externalTerminal"]]
)
def test_exit_normally_with_wait_on_abnormal_exit_enabled(pyfile, target, run):
@pyfile
def code_to_debug():
from debug_me import ptvsd
@ -87,13 +98,14 @@ def test_exit_normally_with_wait_on_abnormal_exit_enabled(pyfile, run_as):
ptvsd.break_into_debugger()
print()
with debug.Session(runners.launch) as session:
session.configure(run_as, code_to_debug, waitOnAbnormalExit=True)
session.start_debugging()
with debug.Session() as session:
session.config["waitOnAbnormalExit"] = True
with run(session, target(code_to_debug)):
pass
session.wait_for_stop()
session.request_continue()
session.wait_for_next_event("exited")
assert not has_waited(session)
session.proceed()