From f3441a67905e7153142386c4e1a79c925efd95a7 Mon Sep 17 00:00:00 2001 From: goodboy Date: Mon, 23 Mar 2026 18:44:14 -0400 Subject: [PATCH] Update tests+examples imports for new subpkgs Adjust all `tractor._state`, `tractor._addr`, `tractor._supervise`, etc. refs in tests and examples to use the new `runtime/`, `discovery/`, `spawn/` paths. Also, - use `tractor.debug_mode()` pub API instead of `tractor._state.debug_mode()` in a few test mods - add explicit `timeout=20` to `test_respawn_consumer_task` `@tractor_test` deco call (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- examples/debugging/fast_error_in_root_after_spawn.py | 2 +- tests/devx/test_tooling.py | 2 +- tests/ipc/test_each_tpt.py | 11 +++++------ tests/ipc/test_multi_tpt.py | 4 ++-- tests/msg/test_pldrx_limiting.py | 2 +- tests/test_context_stream_semantics.py | 4 ++-- tests/test_infected_asyncio.py | 2 +- tests/test_inter_peer_cancellation.py | 6 +++--- tests/test_legacy_one_way_streaming.py | 2 +- tests/test_local.py | 2 +- tests/test_multi_program.py | 6 +++--- tests/test_root_runtime.py | 8 ++++---- 12 files changed, 25 insertions(+), 26 deletions(-) diff --git a/examples/debugging/fast_error_in_root_after_spawn.py b/examples/debugging/fast_error_in_root_after_spawn.py index 86710788..5c2fdce2 100644 --- a/examples/debugging/fast_error_in_root_after_spawn.py +++ b/examples/debugging/fast_error_in_root_after_spawn.py @@ -20,7 +20,7 @@ async def sleep( async def open_ctx( - n: tractor._supervise.ActorNursery + n: tractor.runtime._supervise.ActorNursery ): # spawn both actors diff --git a/tests/devx/test_tooling.py b/tests/devx/test_tooling.py index 0eb19182..c529bed2 100644 --- a/tests/devx/test_tooling.py +++ b/tests/devx/test_tooling.py @@ -126,7 +126,7 @@ def test_shield_pause( child.pid, signal.SIGINT, ) - from tractor._supervise import _shutdown_msg + from tractor.runtime._supervise import _shutdown_msg expect( child, # 'Shutting down actor runtime', diff --git a/tests/ipc/test_each_tpt.py b/tests/ipc/test_each_tpt.py index 9ed45789..5d1fdea3 100644 --- a/tests/ipc/test_each_tpt.py +++ b/tests/ipc/test_each_tpt.py @@ -8,17 +8,16 @@ from pathlib import Path import pytest import trio import tractor -from tractor import ( - Actor, - _state, - _addr, -) +from tractor import Actor +from tractor.runtime import _state +from tractor.discovery import _addr @pytest.fixture def bindspace_dir_str() -> str: - rt_dir: Path = tractor._state.get_rt_dir() + from tractor.runtime._state import get_rt_dir + rt_dir: Path = get_rt_dir() bs_dir: Path = rt_dir / 'doggy' bs_dir_str: str = str(bs_dir) assert not bs_dir.is_dir() diff --git a/tests/ipc/test_multi_tpt.py b/tests/ipc/test_multi_tpt.py index 289f5135..94dae213 100644 --- a/tests/ipc/test_multi_tpt.py +++ b/tests/ipc/test_multi_tpt.py @@ -13,9 +13,9 @@ from tractor import ( Portal, ipc, msg, - _state, - _addr, ) +from tractor.runtime import _state +from tractor.discovery import _addr @tractor.context async def chk_tpts( diff --git a/tests/msg/test_pldrx_limiting.py b/tests/msg/test_pldrx_limiting.py index bb9a3ef7..b180dc03 100644 --- a/tests/msg/test_pldrx_limiting.py +++ b/tests/msg/test_pldrx_limiting.py @@ -61,7 +61,7 @@ async def maybe_expect_raises( Async wrapper for ensuring errors propagate from the inner scope. ''' - if tractor._state.debug_mode(): + if tractor.debug_mode(): timeout += 999 with trio.fail_after(timeout): diff --git a/tests/test_context_stream_semantics.py b/tests/test_context_stream_semantics.py index f860e4d3..6d7de4d6 100644 --- a/tests/test_context_stream_semantics.py +++ b/tests/test_context_stream_semantics.py @@ -26,7 +26,7 @@ from tractor._exceptions import ( StreamOverrun, ContextCancelled, ) -from tractor._state import current_ipc_ctx +from tractor.runtime._state import current_ipc_ctx from tractor._testing import ( tractor_test, @@ -939,7 +939,7 @@ def test_one_end_stream_not_opened( ''' overrunner, buf_size_increase, entrypoint = overrun_by - from tractor._runtime import Actor + from tractor.runtime._runtime import Actor buf_size = buf_size_increase + Actor.msg_buffer_size timeout: float = ( diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index 7b1e952c..9f6b43e5 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -26,8 +26,8 @@ from tractor import ( to_asyncio, RemoteActorError, ContextCancelled, - _state, ) +from tractor.runtime import _state from tractor.trionics import BroadcastReceiver from tractor._testing import expect_ctxc diff --git a/tests/test_inter_peer_cancellation.py b/tests/test_inter_peer_cancellation.py index 42e30345..49854a99 100644 --- a/tests/test_inter_peer_cancellation.py +++ b/tests/test_inter_peer_cancellation.py @@ -201,7 +201,7 @@ async def stream_from_peer( ) -> None: # sanity - assert tractor._state.debug_mode() == debug_mode + assert tractor.debug_mode() == debug_mode peer: Portal try: @@ -841,7 +841,7 @@ async def serve_subactors( async with open_nursery() as an: # sanity - assert tractor._state.debug_mode() == debug_mode + assert tractor.debug_mode() == debug_mode await ctx.started(peer_name) async with ctx.open_stream() as ipc: @@ -880,7 +880,7 @@ async def client_req_subactor( ) -> None: # sanity if debug_mode: - assert tractor._state.debug_mode() + assert tractor.debug_mode() # TODO: other cases to do with sub lifetimes: # -[ ] test that we can have the server spawn a sub diff --git a/tests/test_legacy_one_way_streaming.py b/tests/test_legacy_one_way_streaming.py index 76c95e9f..38f596d6 100644 --- a/tests/test_legacy_one_way_streaming.py +++ b/tests/test_legacy_one_way_streaming.py @@ -353,7 +353,7 @@ def test_not_fast_enough_quad( assert results is None -@tractor_test +@tractor_test(timeout=20) async def test_respawn_consumer_task( reg_addr: tuple, spawn_backend: str, diff --git a/tests/test_local.py b/tests/test_local.py index c6f5047a..b535cb33 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -39,7 +39,7 @@ async def test_self_is_registered_localportal(reg_addr): actor = tractor.current_actor() assert actor.is_arbiter async with tractor.get_registry(reg_addr) as portal: - assert isinstance(portal, tractor._portal.LocalPortal) + assert isinstance(portal, tractor.runtime._portal.LocalPortal) with trio.fail_after(0.2): sockaddr = await portal.run_from_ns( diff --git a/tests/test_multi_program.py b/tests/test_multi_program.py index 20e13f97..f44d036a 100644 --- a/tests/test_multi_program.py +++ b/tests/test_multi_program.py @@ -17,11 +17,11 @@ from tractor._testing import ( ) from tractor import ( current_actor, - _state, Actor, Context, Portal, ) +from tractor.runtime import _state from .conftest import ( sig_prog, _INT_SIGNAL, @@ -30,7 +30,7 @@ from .conftest import ( if TYPE_CHECKING: from tractor.msg import Aid - from tractor._addr import ( + from tractor.discovery._addr import ( UnwrappedAddress, ) @@ -122,7 +122,7 @@ async def get_root_portal( # connect back to our immediate parent which should also # be the actor-tree's root. - from tractor._discovery import get_root + from tractor.discovery._discovery import get_root ptl: Portal async with get_root() as ptl: root_aid: Aid = ptl.chan.aid diff --git a/tests/test_root_runtime.py b/tests/test_root_runtime.py index 6fc39b7d..461e9bd2 100644 --- a/tests/test_root_runtime.py +++ b/tests/test_root_runtime.py @@ -94,15 +94,15 @@ def test_runtime_vars_unset( after the root actor-runtime exits! ''' - assert not tractor._state._runtime_vars['_debug_mode'] + assert not tractor.runtime._state._runtime_vars['_debug_mode'] async def main(): - assert not tractor._state._runtime_vars['_debug_mode'] + assert not tractor.runtime._state._runtime_vars['_debug_mode'] async with tractor.open_nursery( debug_mode=True, ): - assert tractor._state._runtime_vars['_debug_mode'] + assert tractor.runtime._state._runtime_vars['_debug_mode'] # after runtime closure, should be reverted! - assert not tractor._state._runtime_vars['_debug_mode'] + assert not tractor.runtime._state._runtime_vars['_debug_mode'] trio.run(main)