From 9748850657337ba31f220387e4a7777a87ec019a Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 10 Nov 2022 20:34:51 +0000 Subject: [PATCH] Add a unit test for removal ordering via Widget.remove --- tests/test_widget_removing.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_widget_removing.py b/tests/test_widget_removing.py index 5391fe7a0..b0da63d2e 100644 --- a/tests/test_widget_removing.py +++ b/tests/test_widget_removing.py @@ -108,3 +108,19 @@ async def test_remove_move_focus(): assert len(pilot.app.screen.walk_children(with_self=False)) == 6 assert pilot.app.focused is not None assert pilot.app.focused == buttons[9] + +async def test_remove_order(): + """The removal of a top-level widget should cause bottom-first removal.""" + + removals: list[str] = [] + + class Removable(Container): + def on_unmount( self, _ ): + removals.append(self.id if self.id is not None else "unknown") + + async with App().run_test() as pilot: + await pilot.app.mount( + Removable(Removable(Removable(id="grandchild"), id="child"), id="parent") + ) + await pilot.app.screen.children[0].remove() + assert removals == ["grandchild", "child", "parent"]