mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
test for is_attached
This commit is contained in:
@@ -125,8 +125,17 @@ class MessagePump(metaclass=MessagePumpMeta):
|
||||
|
||||
@property
|
||||
def is_attached(self) -> bool:
|
||||
"""Check the node is attached to the DOM"""
|
||||
return self._parent is not None
|
||||
"""Check the node is attached to the app via the DOM."""
|
||||
|
||||
from .app import App
|
||||
|
||||
node = self
|
||||
|
||||
while not isinstance(node, App):
|
||||
if node._parent is None:
|
||||
return False
|
||||
node = node._parent
|
||||
return True
|
||||
|
||||
def _attach(self, parent: MessagePump) -> None:
|
||||
"""Set the parent, and therefore attach this node to the tree.
|
||||
|
||||
@@ -8,9 +8,13 @@ from textual.containers import Container
|
||||
async def test_remove_single_widget():
|
||||
"""It should be possible to the only widget on a screen."""
|
||||
async with App().run_test() as pilot:
|
||||
await pilot.app.mount(Static())
|
||||
widget = Static()
|
||||
assert not widget.is_attached
|
||||
await pilot.app.mount(widget)
|
||||
assert widget.is_attached
|
||||
assert len(pilot.app.screen.children) == 1
|
||||
await pilot.app.query_one(Static).remove()
|
||||
assert not widget.is_attached
|
||||
assert len(pilot.app.screen.children) == 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user