Skip to content

Commit 8581391

Browse files
committed
100% test coverage
1 parent a8c19b8 commit 8581391

File tree

13 files changed

+72
-18
lines changed

13 files changed

+72
-18
lines changed

Diff for: docs/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ RUN sphinx-build -v -W -b html source build
3333
# Define Entrypoint
3434
# -----------------
3535
ENV PORT=5000
36-
ENV REACTPY_DEBUG_MODE=1
36+
ENV REACTPY_DEBUG=1
3737
ENV REACTPY_CHECK_VDOM_SPEC=0
3838
CMD ["python", "main.py"]

Diff for: pyproject.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ xfail_strict = true
117117
asyncio_mode = "auto"
118118
log_cli_level = "INFO"
119119

120-
[tool.hatch.envs.hatch-test.env-vars]
121-
REACTPY_DEBUG_MODE = "1"
122-
123120
#######################################
124121
# >>> Hatch Documentation Scripts <<< #
125122
#######################################
@@ -241,7 +238,7 @@ omit = [
241238
]
242239

243240
[tool.coverage.report]
244-
fail_under = 98
241+
fail_under = 100
245242
show_missing = true
246243
skip_covered = true
247244
sort = "Name"

Diff for: src/reactpy/asgi/utils.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717
def import_dotted_path(dotted_path: str) -> Any:
1818
"""Imports a dotted path and returns the callable."""
1919
if "." not in dotted_path:
20-
raise ValueError(f"{dotted_path!r} is not a valid dotted path.")
20+
raise ValueError(f'"{dotted_path}" is not a valid dotted path.')
2121

2222
module_name, component_name = dotted_path.rsplit(".", 1)
2323

2424
try:
2525
module = import_module(module_name)
2626
except ImportError as error:
27-
msg = f"Failed to import {module_name!r} while loading {component_name!r}"
28-
raise RuntimeError(msg) from error
27+
msg = f'ReactPy failed to import "{module_name}"'
28+
raise ImportError(msg) from error
2929

30-
return getattr(module, component_name)
30+
try:
31+
return getattr(module, component_name)
32+
except AttributeError as error:
33+
msg = f'ReactPy failed to import "{component_name}" from "{module_name}"'
34+
raise AttributeError(msg) from error
3135

3236

3337
def import_components(dotted_paths: Iterable[str]) -> dict[str, Any]:
@@ -111,4 +115,4 @@ def process_settings(settings: ReactPyConfig) -> None:
111115
if config_object:
112116
config_object.set_current(settings[setting]) # type: ignore
113117
else:
114-
raise ValueError(f"Unknown ReactPy setting {setting!r}.")
118+
raise ValueError(f'Unknown ReactPy setting "{setting}".')

Diff for: src/reactpy/core/hooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def use_debug_value(
185185
"""Log debug information when the given message changes.
186186
187187
.. note::
188-
This hook only logs if :data:`~reactpy.config.REACTPY_DEBUG_MODE` is active.
188+
This hook only logs if :data:`~reactpy.config.REACTPY_DEBUG` is active.
189189
190190
Unlike other hooks, a message is considered to have changed if the old and new
191191
values are ``!=``. Because this comparison is performed on every render of the

Diff for: src/reactpy/core/serve.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def _single_outgoing_loop(
6666
msg = (
6767
"Failed to send update. More info may be available "
6868
"if you enabling debug mode by setting "
69-
"`reactpy.config.REACTPY_DEBUG_MODE.current = True`."
69+
"`reactpy.config.REACTPY_DEBUG.current = True`."
7070
)
7171
logger.error(msg)
7272
raise

Diff for: src/reactpy/testing/backend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import uvicorn
1212
from asgiref import typing as asgi_types
1313

14-
from reactpy.asgi.standalone import ReactPy, ReactPyMiddleware
14+
from reactpy.asgi.middleware import ReactPyMiddleware
15+
from reactpy.asgi.standalone import ReactPy
1516
from reactpy.config import REACTPY_TESTS_DEFAULT_TIMEOUT
1617
from reactpy.core.component import component
1718
from reactpy.core.hooks import use_callback, use_effect, use_state

Diff for: src/reactpy/testing/display.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def __aenter__(self) -> DisplayFixture:
6767

6868
self.page.set_default_timeout(REACTPY_TESTS_DEFAULT_TIMEOUT.current * 1000)
6969

70-
if not hasattr(self, "backend"):
70+
if not hasattr(self, "backend"): # pragma: no cover
7171
self.backend = BackendFixture()
7272
await es.enter_async_context(self.backend)
7373

Diff for: tests/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from reactpy.config import (
1212
REACTPY_ASYNC_RENDERING,
13+
REACTPY_DEBUG,
1314
REACTPY_TESTS_DEFAULT_TIMEOUT,
1415
)
1516
from reactpy.testing import (
@@ -19,7 +20,8 @@
1920
clear_reactpy_web_modules_dir,
2021
)
2122

22-
REACTPY_ASYNC_RENDERING.current = True
23+
REACTPY_ASYNC_RENDERING.set_current(True)
24+
REACTPY_DEBUG.set_current(True)
2325
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS", "False") in {
2426
"y",
2527
"yes",

Diff for: tests/test_asgi/test_middleware.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: S701
12
from pathlib import Path
23

34
import pytest

Diff for: tests/test_asgi/test_utils.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
from reactpy import config
4+
from reactpy.asgi import utils
5+
6+
7+
def test_invalid_dotted_path():
8+
with pytest.raises(ValueError, match='"abc" is not a valid dotted path.'):
9+
utils.import_dotted_path("abc")
10+
11+
12+
def test_invalid_component():
13+
with pytest.raises(
14+
AttributeError, match='ReactPy failed to import "foobar" from "reactpy"'
15+
):
16+
utils.import_dotted_path("reactpy.foobar")
17+
18+
19+
def test_invalid_module():
20+
with pytest.raises(ImportError, match='ReactPy failed to import "foo"'):
21+
utils.import_dotted_path("foo.bar")
22+
23+
24+
def test_invalid_vdom_head():
25+
with pytest.raises(ValueError, match="Invalid head element!*"):
26+
utils.vdom_head_to_html({"tagName": "invalid"})
27+
28+
29+
def test_process_settings():
30+
utils.process_settings({"async_rendering": False})
31+
assert config.REACTPY_ASYNC_RENDERING.current is False
32+
utils.process_settings({"async_rendering": True})
33+
assert config.REACTPY_ASYNC_RENDERING.current is True
34+
35+
36+
def test_invalid_setting():
37+
with pytest.raises(ValueError, match='Unknown ReactPy setting "foobar".'):
38+
utils.process_settings({"foobar": True})

Diff for: tests/test_client.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import asyncio
2-
from contextlib import AsyncExitStack
32
from pathlib import Path
43

54
from playwright.async_api import Page
65

76
import reactpy
87
from reactpy.testing import BackendFixture, DisplayFixture, poll
9-
from reactpy.testing.utils import find_available_port
108
from tests.tooling.common import DEFAULT_TYPE_DELAY
119
from tests.tooling.hooks import use_counter
1210

Diff for: tests/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def reset_options():
2323
opt.current = val
2424

2525

26-
def test_reactpy_debug_mode_toggle():
26+
def test_reactpy_debug_toggle():
2727
# just check that nothing breaks
2828
config.REACTPY_DEBUG.current = True
2929
config.REACTPY_DEBUG.current = False

Diff for: tests/test_web/test_utils.py

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from reactpy.testing import assert_reactpy_did_log
77
from reactpy.web.utils import (
8+
_resolve_relative_url,
89
module_name_suffix,
910
resolve_module_exports_from_file,
1011
resolve_module_exports_from_source,
@@ -150,3 +151,15 @@ def test_log_on_unknown_export_type():
150151
assert resolve_module_exports_from_source(
151152
"export something unknown;", exclude_default=False
152153
) == (set(), set())
154+
155+
156+
def test_resolve_relative_url():
157+
assert (
158+
_resolve_relative_url("https://some.url", "path/to/another.js")
159+
== "path/to/another.js"
160+
)
161+
assert (
162+
_resolve_relative_url("https://some.url", "/path/to/another.js")
163+
== "https://some.url/path/to/another.js"
164+
)
165+
assert _resolve_relative_url("/some/path", "to/another.js") == "to/another.js"

0 commit comments

Comments
 (0)