mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Tidy up and extend the DOM spot tests
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
|
from textual.dom import DOMError
|
||||||
|
|
||||||
class Content(Widget):
|
class Content(Widget):
|
||||||
pass
|
pass
|
||||||
@@ -7,6 +10,8 @@ class Body(Widget):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_find_dom_spot():
|
def test_find_dom_spot():
|
||||||
|
|
||||||
|
# Build up a "fake" DOM for an application.
|
||||||
screen = Widget(name="Screen")
|
screen = Widget(name="Screen")
|
||||||
header = Widget(name="Header", id="header")
|
header = Widget(name="Header", id="header")
|
||||||
body = Body(id="body")
|
body = Body(id="body")
|
||||||
@@ -14,9 +19,21 @@ def test_find_dom_spot():
|
|||||||
body._add_children(*content)
|
body._add_children(*content)
|
||||||
footer = Widget(name="Footer", id="footer")
|
footer = Widget(name="Footer", id="footer")
|
||||||
screen._add_children(header, body, footer)
|
screen._add_children(header, body, footer)
|
||||||
|
|
||||||
|
# Just as a quick double-check, make sure the main components are in
|
||||||
|
# their intended place.
|
||||||
assert list(screen.children) == [header,body,footer]
|
assert list(screen.children) == [header,body,footer]
|
||||||
|
|
||||||
|
# Now check that we find what we're looking for in the places we expect
|
||||||
|
# to find them.
|
||||||
assert screen._find_spot(None) == (screen,-1)
|
assert screen._find_spot(None) == (screen,-1)
|
||||||
assert screen._find_spot(1) == (screen, 1)
|
assert screen._find_spot(1) == (screen, 1)
|
||||||
assert screen._find_spot(body) == screen._find_spot(1)
|
assert screen._find_spot(body) == screen._find_spot(1)
|
||||||
assert screen._find_spot("Body") == screen._find_spot(body)
|
assert screen._find_spot("Body") == screen._find_spot(body)
|
||||||
assert screen._find_spot("#body") == screen._find_spot(1)
|
assert screen._find_spot("#body") == screen._find_spot(1)
|
||||||
|
|
||||||
|
# Finally, let's be sure that we get an error if, for some odd reason,
|
||||||
|
# we go looking for a widget that isn't actually part of the DOM we're
|
||||||
|
# looking in.
|
||||||
|
with pytest.raises(DOMError):
|
||||||
|
_ = screen._find_spot(Widget())
|
||||||
|
|||||||
Reference in New Issue
Block a user