Run black over widget removing tests

This commit is contained in:
Dave Pearson
2023-01-09 13:59:59 +00:00
parent 3f6ec10311
commit c84a5dc413

View File

@@ -4,6 +4,7 @@ from textual.widget import Widget
from textual.widgets import Static, Button from textual.widgets import Static, Button
from textual.containers import Container from textual.containers import Container
async def test_remove_single_widget(): async def test_remove_single_widget():
"""It should be possible to the only widget on a screen.""" """It should be possible to the only widget on a screen."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
@@ -12,6 +13,7 @@ async def test_remove_single_widget():
await pilot.app.query_one(Static).remove() await pilot.app.query_one(Static).remove()
assert len(pilot.app.screen.children) == 0 assert len(pilot.app.screen.children) == 0
async def test_many_remove_all_widgets(): async def test_many_remove_all_widgets():
"""It should be possible to remove all widgets on a multi-widget screen.""" """It should be possible to remove all widgets on a multi-widget screen."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
@@ -20,6 +22,7 @@ async def test_many_remove_all_widgets():
await pilot.app.query(Static).remove() await pilot.app.query(Static).remove()
assert len(pilot.app.screen.children) == 0 assert len(pilot.app.screen.children) == 0
async def test_many_remove_some_widgets(): async def test_many_remove_some_widgets():
"""It should be possible to remove some widgets on a multi-widget screen.""" """It should be possible to remove some widgets on a multi-widget screen."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
@@ -28,70 +31,33 @@ async def test_many_remove_some_widgets():
await pilot.app.query(".is-0").remove() await pilot.app.query(".is-0").remove()
assert len(pilot.app.screen.children) == 5 assert len(pilot.app.screen.children) == 5
async def test_remove_branch(): async def test_remove_branch():
"""It should be possible to remove a whole branch in the DOM.""" """It should be possible to remove a whole branch in the DOM."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
await pilot.app.mount( await pilot.app.mount(
Container( Container(Container(Container(Container(Container(Static()))))),
Container(
Container(
Container(
Container(
Static()
)
)
)
)
),
Static(), Static(),
Container( Container(Container(Container(Container(Container(Static()))))),
Container(
Container(
Container(
Container(
Static()
)
)
)
)
),
) )
assert len(pilot.app.screen.walk_children(with_self=False)) == 13 assert len(pilot.app.screen.walk_children(with_self=False)) == 13
await pilot.app.screen.children[0].remove() await pilot.app.screen.children[0].remove()
assert len(pilot.app.screen.walk_children(with_self=False)) == 7 assert len(pilot.app.screen.walk_children(with_self=False)) == 7
async def test_remove_overlap(): async def test_remove_overlap():
"""It should be possible to remove an overlapping collection of widgets.""" """It should be possible to remove an overlapping collection of widgets."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
await pilot.app.mount( await pilot.app.mount(
Container( Container(Container(Container(Container(Container(Static()))))),
Container(
Container(
Container(
Container(
Static()
)
)
)
)
),
Static(), Static(),
Container( Container(Container(Container(Container(Container(Static()))))),
Container(
Container(
Container(
Container(
Static()
)
)
)
)
),
) )
assert len(pilot.app.screen.walk_children(with_self=False)) == 13 assert len(pilot.app.screen.walk_children(with_self=False)) == 13
await pilot.app.query(Container).remove() await pilot.app.query(Container).remove()
assert len(pilot.app.screen.walk_children(with_self=False)) == 1 assert len(pilot.app.screen.walk_children(with_self=False)) == 1
async def test_remove_move_focus(): async def test_remove_move_focus():
"""Removing a focused widget should settle focus elsewhere.""" """Removing a focused widget should settle focus elsewhere."""
async with App().run_test() as pilot: async with App().run_test() as pilot:
@@ -109,6 +75,7 @@ async def test_remove_move_focus():
assert pilot.app.focused is not None assert pilot.app.focused is not None
assert pilot.app.focused == buttons[9] assert pilot.app.focused == buttons[9]
async def test_widget_remove_order(): async def test_widget_remove_order():
"""A Widget.remove of a top-level widget should cause bottom-first removal.""" """A Widget.remove of a top-level widget should cause bottom-first removal."""
@@ -127,6 +94,7 @@ async def test_widget_remove_order():
assert len(pilot.app.screen.walk_children(with_self=False)) == 0 assert len(pilot.app.screen.walk_children(with_self=False)) == 0
assert removals == ["grandchild", "child", "parent"] assert removals == ["grandchild", "child", "parent"]
async def test_query_remove_order(): async def test_query_remove_order():
"""A DOMQuery.remove of a top-level widget should cause bottom-first removal.""" """A DOMQuery.remove of a top-level widget should cause bottom-first removal."""