Skip to content

Commit af672b1

Browse files
committed
fix tests
1 parent b7b8cca commit af672b1

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

src/py/reactpy/reactpy/core/vdom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ def _validate_child_key_integrity(value: Any) -> None:
331331
else:
332332
for child in value:
333333
if isinstance(child, ComponentType) and child.key is None:
334-
warn(f"Key not specified for child in list {child}")
334+
warn(f"Key not specified for child in list {child}", UserWarning)
335335
elif isinstance(child, Mapping) and "key" not in child:
336336
# remove 'children' to reduce log spam
337337
child_copy = {**child, "children": _EllipsisRepr()}
338-
warn(f"Key not specified for child in list {child_copy}")
338+
warn(f"Key not specified for child in list {child_copy}", UserWarning)
339339

340340

341341
class _CustomVdomDictConstructor(Protocol):

src/py/reactpy/tests/test_core/test_hooks.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,12 +1257,3 @@ def bad_effect():
12571257
await layout.render()
12581258
component_hook.latest.schedule_render()
12591259
await layout.render() # no error
1260-
1261-
1262-
@pytest.mark.skipif(
1263-
not REACTPY_DEBUG_MODE.current,
1264-
reason="only check json serialization in debug mode",
1265-
)
1266-
def test_raise_for_non_json_attrs():
1267-
with pytest.raises(TypeError, match="JSON serializable"):
1268-
reactpy.html.div({"non_json_serializable_object": object()})

src/py/reactpy/tests/test_core/test_vdom.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,36 @@ def test_invalid_vdom(value, error_message_pattern):
280280
validate_vdom_json(value)
281281

282282

283-
@pytest.mark.skipif(not REACTPY_DEBUG_MODE.current, reason="Only logs in debug mode")
284-
def test_debug_log_cannot_verify_keypath_for_genereators(caplog):
285-
reactpy.vdom("div", (1 for i in range(10)))
286-
assert len(caplog.records) == 1
287-
assert caplog.records[0].message.startswith(
288-
"Did not verify key-path integrity of children in generator"
289-
)
290-
caplog.records.clear()
291-
283+
@pytest.mark.skipif(not REACTPY_DEBUG_MODE.current, reason="Only warns in debug mode")
284+
def test_warn_cannot_verify_keypath_for_genereators():
285+
with pytest.warns(UserWarning) as record:
286+
reactpy.vdom("div", (1 for i in range(10)))
287+
assert len(record) == 1
288+
assert (
289+
record[0]
290+
.message.args[0]
291+
.startswith("Did not verify key-path integrity of children in generator")
292+
)
292293

293-
@pytest.mark.skipif(not REACTPY_DEBUG_MODE.current, reason="Only logs in debug mode")
294-
def test_debug_log_dynamic_children_must_have_keys(caplog):
295-
reactpy.vdom("div", [reactpy.vdom("div")])
296-
assert len(caplog.records) == 1
297-
assert caplog.records[0].message.startswith("Key not specified for child")
298294

299-
caplog.records.clear()
295+
@pytest.mark.skipif(not REACTPY_DEBUG_MODE.current, reason="Only warns in debug mode")
296+
def test_warn_dynamic_children_must_have_keys():
297+
with pytest.warns(UserWarning) as record:
298+
reactpy.vdom("div", [reactpy.vdom("div")])
299+
assert len(record) == 1
300+
assert record[0].message.args[0].startswith("Key not specified for child")
300301

301302
@reactpy.component
302303
def MyComponent():
303304
return reactpy.vdom("div")
304305

305-
reactpy.vdom("div", [MyComponent()])
306-
assert len(caplog.records) == 1
307-
assert caplog.records[0].message.startswith("Key not specified for child")
306+
with pytest.warns(UserWarning) as record:
307+
reactpy.vdom("div", [MyComponent()])
308+
assert len(record) == 1
309+
assert record[0].message.args[0].startswith("Key not specified for child")
310+
311+
312+
@pytest.mark.skipif(not REACTPY_DEBUG_MODE.current, reason="only checked in debug mode")
313+
def test_raise_for_non_json_attrs():
314+
with pytest.raises(TypeError, match="JSON serializable"):
315+
reactpy.html.div({"non_json_serializable_object": object()})

0 commit comments

Comments
 (0)