@@ -293,71 +293,68 @@ def compose(self):
293
293
yield Input (id = "input2" )
294
294
295
295
296
- @pytest .fixture
297
- async def simple_app ():
298
- """Async fixture for SimpleApp."""
299
- app = SimpleApp ()
300
- async with app .run_test (): # Use async with for compatibility with older versions
301
- yield app
302
-
303
-
304
- @pytest .mark .asyncio
305
- async def test_query_union_type (simple_app : SimpleApp ):
296
+ async def test_query_union_type ():
306
297
# Test with a UnionType
307
- results = simple_app .query (Input | Select )
308
- assert len (results ) == 3
309
- assert {w .id for w in results } == {"input1" , "select1" , "input2" }
298
+ simple_app = SimpleApp ()
299
+ async with simple_app .run_test ():
300
+ results = simple_app .query (Input | Select )
301
+ assert len (results ) == 3
302
+ assert {w .id for w in results } == {"input1" , "select1" , "input2" }
310
303
311
- # Test with a single type
312
- results2 = simple_app .query (Input )
313
- assert len (results2 ) == 2
314
- assert {w .id for w in results2 } == {"input1" , "input2" }
304
+ # Test with a single type
305
+ results2 = simple_app .query (Input )
306
+ assert len (results2 ) == 2
307
+ assert {w .id for w in results2 } == {"input1" , "input2" }
315
308
316
- # Test with string selector
317
- results3 = simple_app .query ("#input1" )
318
- assert len (results3 ) == 1
319
- assert results3 [0 ].id == "input1"
309
+ # Test with string selector
310
+ results3 = simple_app .query ("#input1" )
311
+ assert len (results3 ) == 1
312
+ assert results3 [0 ].id == "input1"
320
313
321
314
322
- @pytest .mark .asyncio
323
- async def test_query_nested_unions (simple_app : SimpleApp ):
315
+ async def test_query_nested_unions ():
324
316
"""Test handling of nested unions."""
325
- # Create nested union types
326
- InputOrSelect = Input | Select
327
- InputSelectOrStatic = InputOrSelect | Static
328
317
329
- # Test nested union query
330
- results = simple_app .query (InputSelectOrStatic )
318
+ simple_app = SimpleApp ()
319
+ async with simple_app .run_test ():
320
+ # Create nested union types
321
+ InputOrSelect = Input | Select
322
+ InputSelectOrStatic = InputOrSelect | Static
331
323
332
- # Verify that we find all our explicitly defined widgets
333
- widget_ids = {w .id for w in results if w .id is not None }
334
- expected_ids = {"input1" , "select1" , "static1" , "input2" }
335
- assert expected_ids .issubset (widget_ids ), "Not all expected widgets were found"
324
+ # Test nested union query
325
+ results = simple_app .query (InputSelectOrStatic )
336
326
337
- # Verify we get the right types of widgets
338
- assert all ( isinstance ( w , ( Input , Select , Static )) for w in results ), (
339
- "Found unexpected widget types"
340
- )
327
+ # Verify that we find all our explicitly defined widgets
328
+ widget_ids = { w . id for w in results if w . id is not None }
329
+ expected_ids = { "input1" , "select1" , "static1" , "input2" }
330
+ assert expected_ids . issubset ( widget_ids ), "Not all expected widgets were found"
341
331
342
- # Verify each expected widget appears exactly once
343
- for expected_id in expected_ids :
344
- matching_widgets = [w for w in results if w .id == expected_id ]
345
- assert len (matching_widgets ) == 1 , (
346
- f"Widget with id { expected_id } should appear exactly once"
347
- )
332
+ # Verify we get the right types of widgets
333
+ assert all (
334
+ isinstance (w , (Input , Select , Static )) for w in results
335
+ ), "Found unexpected widget types"
348
336
337
+ # Verify each expected widget appears exactly once
338
+ for expected_id in expected_ids :
339
+ matching_widgets = [w for w in results if w .id == expected_id ]
340
+ assert (
341
+ len (matching_widgets ) == 1
342
+ ), f"Widget with id { expected_id } should appear exactly once"
349
343
350
- @ pytest . mark . asyncio
351
- async def test_query_empty_union (simple_app : SimpleApp ):
344
+
345
+ async def test_query_empty_union ():
352
346
"""Test querying with empty or invalid unions."""
353
347
354
348
class AnotherWidget (Widget ):
355
349
pass
356
350
357
- # Test with a type that exists but has no matches
358
- results = simple_app .query (AnotherWidget )
359
- assert len (results ) == 0
351
+ simple_app = SimpleApp ()
352
+ async with simple_app .run_test ():
353
+
354
+ # Test with a type that exists but has no matches
355
+ results = simple_app .query (AnotherWidget )
356
+ assert len (results ) == 0
360
357
361
- # Test with widget union that has no matches
362
- results = simple_app .query (AnotherWidget | AnotherWidget )
363
- assert len (results ) == 0
358
+ # Test with widget union that has no matches
359
+ results = simple_app .query (AnotherWidget | AnotherWidget )
360
+ assert len (results ) == 0
0 commit comments