MCPcopy
hub / github.com/Textualize/textual / test_width

Function test_width

tests/test_box_model.py:47–93  ·  view source on GitHub ↗

Test width settings.

()

Source from the content-addressed store, hash-verified

45
46
47async def test_width():
48 """Test width settings."""
49
50 one = Fraction(1)
51
52 class TestWidget(Widget):
53 def get_content_width(self, container: Size, parent: Size) -> int:
54 return 10
55
56 def get_content_height(self, container: Size, parent: Size, width: int) -> int:
57 return 10
58
59 widget = TestWidget()
60 styles = widget.styles
61 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
62 assert box_model == BoxModel(Fraction(60), Fraction(20), Spacing(0, 0, 0, 0))
63
64 # Add a margin and check that it is reported
65 styles.margin = (1, 2, 3, 4)
66
67 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
68 assert box_model == BoxModel(Fraction(54), Fraction(16), Spacing(1, 2, 3, 4))
69
70 # Set width to auto-detect
71 styles.width = "auto"
72
73 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
74 # Setting width to auto should call get_auto_width
75 assert box_model == BoxModel(Fraction(10), Fraction(16), Spacing(1, 2, 3, 4))
76
77 # Set width to 100 vw which should make it the width of the parent
78 styles.width = "100vw"
79
80 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
81 assert box_model == BoxModel(Fraction(80), Fraction(16), Spacing(1, 2, 3, 4))
82
83 # Set the width to 100% should make it fill the container size
84 styles.width = "100%"
85
86 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
87 assert box_model == BoxModel(Fraction(54), Fraction(16), Spacing(1, 2, 3, 4))
88
89 styles.width = "100vw"
90 styles.max_width = "50%"
91
92 box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one)
93 assert box_model == BoxModel(Fraction(27), Fraction(16), Spacing(1, 2, 3, 4))
94
95
96async def test_height():

Callers

nothing calls this directly

Calls 5

SizeClass · 0.90
BoxModelClass · 0.90
SpacingClass · 0.90
_get_box_modelMethod · 0.80
TestWidgetClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…