@@ -280,28 +280,36 @@ def test_invalid_vdom(value, error_message_pattern):
280
280
validate_vdom_json (value )
281
281
282
282
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
+ )
292
293
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" )
298
294
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" )
300
301
301
302
@reactpy .component
302
303
def MyComponent ():
303
304
return reactpy .vdom ("div" )
304
305
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