Skip to content

Commit a13d21a

Browse files
committed
fix CI errors
1 parent 15b6afb commit a13d21a

File tree

10 files changed

+67
-17
lines changed

10 files changed

+67
-17
lines changed

src/reactpy/core/hooks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ async def effect(stop: asyncio.Event) -> None:
266266
# Prevent task cancellation if the user enabled shielding
267267
if not shield:
268268
task.cancel()
269-
await asyncio.shield(task)
269+
with contextlib.suppress(asyncio.CancelledError):
270+
await task
270271

271272
# Run the clean-up function when the effect is stopped,
272273
# if it hasn't been run already by a new effect

src/reactpy/executors/pyscript/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def minify_python(source: str) -> str:
4949

5050

5151
def pyscript_executor_html(
52-
file_paths: Sequence[str], uuid: str, root: str, cache_handler: Callable
52+
file_paths: Sequence[str],
53+
uuid: str,
54+
root: str,
55+
cache_handler: Callable | None = None,
5356
) -> str:
5457
"""Inserts the user's code into the PyScript template using pattern matching."""
5558
# Create a valid PyScript executor by replacing the template values

src/reactpy/testing/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from reactpy.testing.backend import BackendFixture
2-
from reactpy.testing.common import GITHUB_ACTIONS, HookCatcher, StaticEventHandler, poll
2+
from reactpy.testing.common import (
3+
DEFAULT_TYPE_DELAY,
4+
HookCatcher,
5+
StaticEventHandler,
6+
poll,
7+
)
38
from reactpy.testing.display import DisplayFixture
49
from reactpy.testing.logs import (
510
LogAssertionError,
@@ -9,7 +14,7 @@
914
)
1015

1116
__all__ = [
12-
"GITHUB_ACTIONS",
17+
"DEFAULT_TYPE_DELAY",
1318
"BackendFixture",
1419
"DisplayFixture",
1520
"HookCatcher",

src/reactpy/testing/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
from reactpy.config import REACTPY_TESTS_DEFAULT_TIMEOUT
1313
from reactpy.core._life_cycle_hook import HOOK_STACK, LifeCycleHook
1414
from reactpy.core.events import EventHandler, to_event_handler_function
15+
from reactpy.utils import GITHUB_ACTIONS
1516

1617
_P = ParamSpec("_P")
1718
_R = TypeVar("_R")
1819

1920

2021
_DEFAULT_POLL_DELAY = 0.1
22+
DEFAULT_TYPE_DELAY = 250 if GITHUB_ACTIONS else 25
2123

2224

2325
class poll(Generic[_R]): # noqa: N801

tests/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from pathlib import Path
33

44
import reactpy
5-
from reactpy.testing import BackendFixture, DisplayFixture, poll
6-
from tests.tooling.common import DEFAULT_TYPE_DELAY
5+
from reactpy.testing import DEFAULT_TYPE_DELAY, BackendFixture, DisplayFixture, poll
76
from tests.tooling.hooks import use_counter
87

98
JS_DIR = Path(__file__).parent / "js"

tests/test_core/test_events.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
to_event_handler_function,
1313
)
1414
from reactpy.core.layout import Layout
15-
from reactpy.testing import DisplayFixture, poll
15+
from reactpy.testing import DEFAULT_TYPE_DELAY, DisplayFixture, poll
1616
from reactpy.types import Event
17-
from tests.tooling.common import DEFAULT_TYPE_DELAY
1817

1918

2019
def test_event_handler_repr():

tests/test_core/test_hooks.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
from reactpy.core._life_cycle_hook import LifeCycleHook
99
from reactpy.core.hooks import strictly_equal, use_effect
1010
from reactpy.core.layout import Layout
11-
from reactpy.testing import DisplayFixture, HookCatcher, assert_reactpy_did_log, poll
11+
from reactpy.testing import (
12+
DEFAULT_TYPE_DELAY,
13+
DisplayFixture,
14+
HookCatcher,
15+
assert_reactpy_did_log,
16+
poll,
17+
)
1218
from reactpy.testing.logs import assert_reactpy_did_not_log
1319
from reactpy.utils import Ref
14-
from tests.tooling.common import DEFAULT_TYPE_DELAY, update_message
20+
from tests.tooling.common import update_message
1521

1622

1723
async def test_must_be_rendering_in_layout_to_use_hooks():
@@ -600,6 +606,46 @@ async def effect():
600606
event_that_never_occurs.set()
601607

602608

609+
async def test_use_async_effect_shield():
610+
component_hook = HookCatcher()
611+
effect_ran = asyncio.Event()
612+
effect_finished = asyncio.Event()
613+
stop_waiting = asyncio.Event()
614+
615+
@reactpy.component
616+
@component_hook.capture
617+
def ComponentWithShieldedEffect():
618+
@reactpy.hooks.use_async_effect(dependencies=None, shield=True)
619+
async def effect():
620+
effect_ran.set()
621+
await stop_waiting.wait()
622+
effect_finished.set()
623+
624+
return reactpy.html.div()
625+
626+
async with Layout(ComponentWithShieldedEffect()) as layout:
627+
await layout.render()
628+
629+
await effect_ran.wait()
630+
631+
# Trigger re-render which would normally cancel the effect
632+
component_hook.latest.schedule_render()
633+
634+
# Give the loop a chance to process the render logic and potentially cancel
635+
await asyncio.sleep(0.1)
636+
637+
# Verify effect hasn't finished yet but also wasn't cancelled
638+
assert not effect_finished.is_set()
639+
640+
# Now allow the effect to finish
641+
stop_waiting.set()
642+
643+
# The re-render should complete now that the shielded effect is done
644+
await layout.render()
645+
646+
await asyncio.wait_for(effect_finished.wait(), 1)
647+
648+
603649
async def test_async_effect_sleep_is_cancelled_on_re_render():
604650
"""Test that async effects waiting on asyncio.sleep are properly cancelled."""
605651
component_hook = HookCatcher()

tests/test_html.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from playwright.async_api import expect
33

44
from reactpy import component, config, hooks, html
5-
from reactpy.testing import DisplayFixture, poll
5+
from reactpy.testing import DEFAULT_TYPE_DELAY, DisplayFixture, poll
66
from reactpy.utils import Ref
7-
from tests.tooling.common import DEFAULT_TYPE_DELAY
87
from tests.tooling.hooks import use_counter
98

109

tests/test_widgets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from pathlib import Path
33

44
import reactpy
5-
from reactpy.testing import DisplayFixture, poll
6-
from tests.tooling.common import DEFAULT_TYPE_DELAY
5+
from reactpy.testing import DEFAULT_TYPE_DELAY, DisplayFixture, poll
76

87
HERE = Path(__file__).parent
98

tests/tooling/common.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any
22

3-
from reactpy.testing.common import GITHUB_ACTIONS
43
from reactpy.types import LayoutEventMessage, LayoutUpdateMessage
54

6-
DEFAULT_TYPE_DELAY = 250 if GITHUB_ACTIONS else 50
7-
85

96
def event_message(target: str, *data: Any) -> LayoutEventMessage:
107
return {"type": "layout-event", "target": target, "data": data}

0 commit comments

Comments
 (0)