From 131e3e81570b126dfcca3cbb7fd0cbd19dd8fcdc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 10 Jul 2024 15:40:44 -0400 Subject: [PATCH] Move `mk_cmd()` to `._testing` Since we're going to need it more generally for `.devx` sub-sys tooling tests. Also, up the sync-pause ctl-c delay another 10ms.. --- tests/test_debugger.py | 36 +++++++++++++++++++----------------- tractor/_testing/__init__.py | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/tests/test_debugger.py b/tests/test_debugger.py index 7acf984..273451b 100644 --- a/tests/test_debugger.py +++ b/tests/test_debugger.py @@ -13,7 +13,6 @@ TODO: from functools import partial import itertools import platform -import pathlib import time import pytest @@ -29,7 +28,7 @@ from tractor.devx._debug import ( _repl_fail_msg, ) from tractor._testing import ( - examples_dir, + mk_cmd, ) from conftest import ( _ci_env, @@ -52,15 +51,6 @@ if platform.system() == 'Windows': ) -def mk_cmd(ex_name: str) -> str: - ''' - Generate a command suitable to pass to ``pexpect.spawn()``. - - ''' - script_path: pathlib.Path = examples_dir() / 'debugging' / f'{ex_name}.py' - return ' '.join(['python', str(script_path)]) - - # TODO: was trying to this xfail style but some weird bug i see in CI # that's happening at collect time.. pretty soon gonna dump actions i'm # thinkin... @@ -84,19 +74,31 @@ def spawn( start_method, testdir, reg_addr, -) -> 'pexpect.spawn': +) -> 'pexpect.spawn': + ''' + Use the `pexpect` module shipped via `testdir.spawn()` to + run an `./examples/..` script by name. + + ''' if start_method != 'trio': pytest.skip( - "Debugger tests are only supported on the trio backend" + '`pexpect` based tests only supported on `trio` backend' ) - def _spawn(cmd): + def _spawn( + cmd: str, + **mkcmd_kwargs, + ): return testdir.spawn( - cmd=mk_cmd(cmd), + cmd=mk_cmd( + cmd, + **mkcmd_kwargs, + ), expect_timeout=3, ) + # such that test-dep can pass input script name. return _spawn @@ -1121,7 +1123,7 @@ def test_pause_from_sync( # `subactor` suffers a race where the root/parent # sends an actor-cancel prior to it hitting its pause # point; by def the value is 0.1 - delay=0.3, + delay=0.4, ) # XXX, fwiw without a brief sleep here the SIGINT might actually @@ -1190,7 +1192,7 @@ def test_pause_from_sync( child, patt=attach_key, # NOTE same as comment above - delay=0.3, + delay=0.4, ) child.sendline('c') diff --git a/tractor/_testing/__init__.py b/tractor/_testing/__init__.py index fd79fe2..1f6624e 100644 --- a/tractor/_testing/__init__.py +++ b/tractor/_testing/__init__.py @@ -54,6 +54,25 @@ def examples_dir() -> pathlib.Path: return repodir() / 'examples' +def mk_cmd( + ex_name: str, + exs_subpath: str = 'debugging', +) -> str: + ''' + Generate a shell command suitable to pass to ``pexpect.spawn()``. + + ''' + script_path: pathlib.Path = ( + examples_dir() + / exs_subpath + / f'{ex_name}.py' + ) + return ' '.join([ + 'python', + str(script_path) + ]) + + @acm async def expect_ctxc( yay: bool,