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

docs/Dockerfile

Lines changed: 1 addition & 1 deletion
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"]

pyproject.toml

Lines changed: 1 addition & 4 deletions
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"

src/reactpy/asgi/utils.py

Lines changed: 9 additions & 5 deletions
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}".')

src/reactpy/core/hooks.py

Lines changed: 1 addition & 1 deletion
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

src/reactpy/core/serve.py

Lines changed: 1 addition & 1 deletion
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

src/reactpy/testing/backend.py

Lines changed: 2 additions & 1 deletion
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

src/reactpy/testing/display.py

Lines changed: 1 addition & 1 deletion
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

tests/conftest.py

Lines changed: 3 additions & 1 deletion
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",

tests/test_asgi/test_middleware.py

Lines changed: 1 addition & 0 deletions
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

tests/test_asgi/test_utils.py

Lines changed: 38 additions & 0 deletions
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})

0 commit comments

Comments
 (0)