Skip to content

Commit 03b8f2c

Browse files
committed
Fix router in local environment
1 parent e96a512 commit 03b8f2c

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

.editorconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
charset = utf-8
11+
end_of_line = lf
12+
13+
[*.py]
14+
indent_size = 4
15+
max_line_length = 120
16+
17+
[*.md]
18+
indent_size = 4
19+
20+
[*.html]
21+
max_line_length = off
22+
23+
[*.js]
24+
max_line_length = off
25+
26+
[*.css]
27+
indent_size = 4
28+
max_line_length = off
29+
30+
# Tests can violate line width restrictions in the interest of clarity.
31+
[**/test_*.py]
32+
max_line_length = off

src/reactpy_router/core.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def router_component(
7474
History( # type: ignore
7575
{"on_change": lambda event: set_location(Location(**event))}
7676
),
77-
route_elements,
77+
html._(route_elements),
7878
value=Connection(old_conn.scope, location, old_conn.carrier),
7979
)
8080

@@ -92,16 +92,14 @@ def link(*children: VdomChild, to: str, **attributes: Any) -> VdomDict:
9292
"onClick": lambda event: set_location(Location(**event)),
9393
"id": uuid,
9494
}
95-
return html._(
96-
html.a(attrs, *children), html.script(link_js_content.replace("UUID", uuid))
97-
)
95+
return html._(html.a(attrs, *children), html.script(link_js_content.replace("UUID", uuid)))
9896

9997

10098
def use_params() -> dict[str, Any]:
10199
"""The `use_params` hook returns an object of key/value pairs of the dynamic params \
102100
from the current URL that were matched by the `Route`. Child routes inherit all params \
103101
from their parent routes.
104-
102+
105103
For example, if you have a `URL_PARAM` defined in the route `/example/<URL_PARAM>/`,
106104
this hook will return the URL_PARAM value that was matched."""
107105

@@ -163,14 +161,10 @@ def _match_route(
163161

164162

165163
History = export(
166-
module_from_file(
167-
"reactpy-router", file=Path(__file__).parent / "static" / "bundle.js"
168-
),
164+
module_from_file("reactpy-router", file=Path(__file__).parent / "static" / "bundle.js"),
169165
("History"),
170166
)
171-
link_js_content = (Path(__file__).parent / "static" / "link.js").read_text(
172-
encoding="utf-8"
173-
)
167+
link_js_content = (Path(__file__).parent / "static" / "link.js").read_text(encoding="utf-8")
174168

175169

176170
@dataclass

tests/conftest.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1+
import asyncio
2+
import sys
3+
14
import pytest
25
from playwright.async_api import async_playwright
36
from reactpy.testing import BackendFixture, DisplayFixture
47

58

69
def pytest_addoption(parser) -> None:
710
parser.addoption(
8-
"--headed",
9-
dest="headed",
10-
action="store_true",
11-
help="Open a browser window when runnging web-based tests",
11+
"--headless",
12+
dest="headless",
13+
action="store_false",
14+
help="Hide the browser window when running web-based tests",
1215
)
1316

1417

1518
@pytest.fixture
1619
async def display(backend, browser):
17-
async with DisplayFixture(backend, browser) as display:
18-
display.page.set_default_timeout(10000)
19-
yield display
20+
if sys.platform == "win32":
21+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
22+
async with DisplayFixture(backend, browser) as display_fixture:
23+
display_fixture.page.set_default_timeout(10000)
24+
yield display_fixture
2025

2126

2227
@pytest.fixture
2328
async def backend():
24-
async with BackendFixture() as backend:
25-
yield backend
29+
async with BackendFixture() as backend_fixture:
30+
yield backend_fixture
2631

2732

2833
@pytest.fixture
2934
async def browser(pytestconfig):
3035
async with async_playwright() as pw:
31-
yield await pw.chromium.launch(headless=not bool(pytestconfig.option.headed))
36+
yield await pw.chromium.launch(headless=False)

0 commit comments

Comments
 (0)