22
33import asyncio
44import inspect
5+ import os
56import time
67from collections .abc import Awaitable , Callable , Coroutine
78from functools import wraps
8- from typing import Any , Generic , ParamSpec , TypeVar , cast
9+ from typing import TYPE_CHECKING , Any , Generic , ParamSpec , TypeVar , cast
910from uuid import uuid4
1011from weakref import ref
1112
12- from reactpy .config import REACTPY_TESTS_DEFAULT_TIMEOUT
13- from reactpy .core ._life_cycle_hook import HOOK_STACK , LifeCycleHook
14- from reactpy .core .events import EventHandler , to_event_handler_function
15- from reactpy .utils import GITHUB_ACTIONS
13+ if TYPE_CHECKING :
14+ from reactpy .core ._life_cycle_hook import LifeCycleHook
15+ from reactpy .core .events import EventHandler
1616
1717_P = ParamSpec ("_P" )
1818_R = TypeVar ("_R" )
1919
2020
2121_DEFAULT_POLL_DELAY = 0.1
22+ GITHUB_ACTIONS = os .getenv ("GITHUB_ACTIONS" , "" ).lower () in {
23+ "y" ,
24+ "yes" ,
25+ "t" ,
26+ "true" ,
27+ "on" ,
28+ "1" ,
29+ }
2230DEFAULT_TYPE_DELAY = 250 if GITHUB_ACTIONS else 25
2331
2432
@@ -47,11 +55,16 @@ async def async_func(*args: _P.args, **kwargs: _P.kwargs) -> _R:
4755 async def until (
4856 self ,
4957 condition : Callable [[_R ], bool ],
50- timeout : float = REACTPY_TESTS_DEFAULT_TIMEOUT . current ,
58+ timeout : float | None = None ,
5159 delay : float = _DEFAULT_POLL_DELAY ,
5260 description : str = "condition to be true" ,
5361 ) -> None :
5462 """Check that the coroutines result meets a condition within the timeout"""
63+ if timeout is None :
64+ from reactpy .config import REACTPY_TESTS_DEFAULT_TIMEOUT
65+
66+ timeout = REACTPY_TESTS_DEFAULT_TIMEOUT .current
67+
5568 started_at = time .time ()
5669 while True :
5770 await asyncio .sleep (delay )
@@ -65,7 +78,7 @@ async def until(
6578 async def until_is (
6679 self ,
6780 right : _R ,
68- timeout : float = REACTPY_TESTS_DEFAULT_TIMEOUT . current ,
81+ timeout : float | None = None ,
6982 delay : float = _DEFAULT_POLL_DELAY ,
7083 ) -> None :
7184 """Wait until the result is identical to the given value"""
@@ -79,7 +92,7 @@ async def until_is(
7992 async def until_equals (
8093 self ,
8194 right : _R ,
82- timeout : float = REACTPY_TESTS_DEFAULT_TIMEOUT . current ,
95+ timeout : float | None = None ,
8396 delay : float = _DEFAULT_POLL_DELAY ,
8497 ) -> None :
8598 """Wait until the result is equal to the given value"""
@@ -132,6 +145,8 @@ def capture(self, render_function: Callable[..., Any]) -> Callable[..., Any]:
132145
133146 @wraps (render_function )
134147 def wrapper (* args : Any , ** kwargs : Any ) -> Any :
148+ from reactpy .core ._life_cycle_hook import HOOK_STACK
149+
135150 self = self_ref ()
136151 if self is None :
137152 raise RuntimeError ("Hook catcher has been garbage collected" )
@@ -196,6 +211,8 @@ def use(
196211 stop_propagation : bool = False ,
197212 prevent_default : bool = False ,
198213 ) -> EventHandler :
214+ from reactpy .core .events import EventHandler , to_event_handler_function
215+
199216 return EventHandler (
200217 to_event_handler_function (function ),
201218 stop_propagation ,
0 commit comments