Skip to content

Commit 631199e

Browse files
committed
This pattern doesn't work with current pytest.
1 parent 121bff6 commit 631199e

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2525
### Added
2626

2727
- Added `pointer_x`, `pointer_y`, `pointer_screen_x`, and `pointer_screen_y` attributes to mouse events https://github.com/Textualize/textual/pull/5556
28+
- DOMNode.query now accepts UnionType for selector, e.g. `self.query(Input | Select )` https://github.com/Textualize/textual/pull/5578
2829

2930
### Changed
3031

tests/test_dom.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -293,71 +293,68 @@ def compose(self):
293293
yield Input(id="input2")
294294

295295

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():
306297
# 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"}
310303

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"}
315308

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"
320313

321314

322-
@pytest.mark.asyncio
323-
async def test_query_nested_unions(simple_app: SimpleApp):
315+
async def test_query_nested_unions():
324316
"""Test handling of nested unions."""
325-
# Create nested union types
326-
InputOrSelect = Input | Select
327-
InputSelectOrStatic = InputOrSelect | Static
328317

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
331323

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)
336326

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"
341331

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"
348336

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"
349343

350-
@pytest.mark.asyncio
351-
async def test_query_empty_union(simple_app: SimpleApp):
344+
345+
async def test_query_empty_union():
352346
"""Test querying with empty or invalid unions."""
353347

354348
class AnotherWidget(Widget):
355349
pass
356350

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
360357

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

Comments
 (0)