Skip to content

Commit b5be02e

Browse files
committed
Revert "Move GITHUB_ACTIONS out of testing module"
This reverts commit 5171a1a.
1 parent 8c68d4a commit b5be02e

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

src/reactpy/executors/pyscript/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
import reactpy
1919
from reactpy.config import REACTPY_DEBUG, REACTPY_PATH_PREFIX, REACTPY_WEB_MODULES_DIR
20+
from reactpy.testing.common import GITHUB_ACTIONS
2021
from reactpy.types import VdomDict
21-
from reactpy.utils import GITHUB_ACTIONS, reactpy_to_string
22+
from reactpy.utils import reactpy_to_string
2223

2324
if TYPE_CHECKING:
2425
from collections.abc import Sequence

src/reactpy/testing/backend.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
from collections.abc import Callable
77
from contextlib import AsyncExitStack
88
from types import TracebackType
9-
from typing import Any
9+
from typing import TYPE_CHECKING, Any
1010
from urllib.parse import urlencode, urlunparse
1111

1212
import uvicorn
1313

14-
from reactpy.core.component import component
15-
from reactpy.core.hooks import use_callback, use_effect, use_state
16-
from reactpy.executors.asgi.middleware import ReactPyMiddleware
17-
from reactpy.executors.asgi.standalone import ReactPy
18-
from reactpy.executors.asgi.types import AsgiApp
1914
from reactpy.testing.logs import (
2015
LogAssertionError,
2116
capture_reactpy_logs,
2217
list_logged_exceptions,
2318
)
24-
from reactpy.types import ComponentConstructor
25-
from reactpy.utils import Ref
19+
20+
if TYPE_CHECKING:
21+
from reactpy.executors.asgi.types import AsgiApp
22+
from reactpy.types import ComponentConstructor
23+
from reactpy.utils import Ref
2624

2725

2826
class BackendFixture:
@@ -48,6 +46,9 @@ def __init__(
4846
port: int | None = None,
4947
**reactpy_config: Any,
5048
) -> None:
49+
from reactpy.executors.asgi.middleware import ReactPyMiddleware
50+
from reactpy.executors.asgi.standalone import ReactPy
51+
5152
self.host = host
5253
self.port = port or 0
5354
self.mount = mount_to_hotswap
@@ -201,6 +202,10 @@ def DivTwo(self):
201202
202203
# displaying the output now will show DivTwo
203204
"""
205+
from reactpy.core.component import component
206+
from reactpy.core.hooks import use_callback, use_effect, use_state
207+
from reactpy.utils import Ref
208+
204209
constructor_ref: Ref[Callable[[], Any]] = Ref(lambda: None)
205210

206211
if update_on_change:

src/reactpy/testing/common.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
import asyncio
44
import inspect
5+
import os
56
import time
67
from collections.abc import Awaitable, Callable, Coroutine
78
from functools import wraps
8-
from typing import Any, Generic, ParamSpec, TypeVar, cast
9+
from typing import TYPE_CHECKING, Any, Generic, ParamSpec, TypeVar, cast
910
from uuid import uuid4
1011
from 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+
}
2230
DEFAULT_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,

src/reactpy/testing/display.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
from playwright.async_api import Browser, Page, async_playwright, expect
1010

11-
from reactpy.config import REACTPY_TESTS_DEFAULT_TIMEOUT as DEFAULT_TIMEOUT
1211
from reactpy.testing.backend import BackendFixture
13-
from reactpy.types import RootComponentConstructor
1412

1513
if TYPE_CHECKING:
1614
import pytest
1715

16+
from reactpy.types import RootComponentConstructor
17+
1818
_logger = getLogger(__name__)
1919

2020

@@ -32,6 +32,8 @@ def __init__(
3232
headless: bool = False,
3333
timeout: float | None = None,
3434
) -> None:
35+
from reactpy.config import REACTPY_TESTS_DEFAULT_TIMEOUT as DEFAULT_TIMEOUT
36+
3537
if backend:
3638
self.backend_is_external = True
3739
self.backend = backend

src/reactpy/testing/logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from traceback import format_exception
88
from typing import Any, NoReturn
99

10-
from reactpy.logging import ROOT_LOGGER
11-
1210

1311
class LogAssertionError(AssertionError):
1412
"""An assertion error raised in relation to log messages."""
@@ -127,6 +125,8 @@ def capture_reactpy_logs() -> Iterator[list[logging.LogRecord]]:
127125
128126
Any logs produced in this context are cleared afterwards
129127
"""
128+
from reactpy.logging import ROOT_LOGGER
129+
130130
original_level = ROOT_LOGGER.level
131131
ROOT_LOGGER.setLevel(logging.DEBUG)
132132
try:

src/reactpy/utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import os
43
import re
54
from collections.abc import Callable, Iterable
65
from importlib import import_module
@@ -17,14 +16,6 @@
1716
_RefValue = TypeVar("_RefValue")
1817
_ModelTransform = Callable[[VdomDict], Any]
1918
_UNDEFINED: Any = object()
20-
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS", "").lower() in {
21-
"y",
22-
"yes",
23-
"t",
24-
"true",
25-
"on",
26-
"1",
27-
}
2819

2920

3021
class Ref(Generic[_RefValue]):

0 commit comments

Comments
 (0)