Test height settings.
()
| 94 | |
| 95 | |
| 96 | async def test_height(): |
| 97 | """Test height settings.""" |
| 98 | |
| 99 | one = Fraction(1) |
| 100 | |
| 101 | class TestWidget(Widget): |
| 102 | def get_content_width(self, container: Size, parent: Size) -> int: |
| 103 | return 10 |
| 104 | |
| 105 | def get_content_height(self, container: Size, parent: Size, width: int) -> int: |
| 106 | return 10 |
| 107 | |
| 108 | widget = TestWidget() |
| 109 | styles = widget.styles |
| 110 | |
| 111 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 112 | assert box_model == BoxModel(Fraction(60), Fraction(20), Spacing(0, 0, 0, 0)) |
| 113 | |
| 114 | # Add a margin and check that it is reported |
| 115 | styles.margin = (1, 2, 3, 4) |
| 116 | |
| 117 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 118 | assert box_model == BoxModel(Fraction(54), Fraction(16), Spacing(1, 2, 3, 4)) |
| 119 | |
| 120 | # Set height to 100 vw which should make it the height of the parent |
| 121 | styles.height = "100vh" |
| 122 | |
| 123 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 124 | assert box_model == BoxModel(Fraction(54), Fraction(24), Spacing(1, 2, 3, 4)) |
| 125 | |
| 126 | # Set the height to 100% should make it fill the container size |
| 127 | styles.height = "100%" |
| 128 | |
| 129 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 130 | assert box_model == BoxModel(Fraction(54), Fraction(16), Spacing(1, 2, 3, 4)) |
| 131 | |
| 132 | styles.height = "auto" |
| 133 | styles.margin = 2 |
| 134 | |
| 135 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 136 | assert box_model == BoxModel(Fraction(56), Fraction(10), Spacing(2, 2, 2, 2)) |
| 137 | |
| 138 | styles.margin = 1, 2, 3, 4 |
| 139 | styles.height = "100vh" |
| 140 | styles.max_height = "50%" |
| 141 | |
| 142 | box_model = widget._get_box_model(Size(60, 20), Size(80, 24), one, one) |
| 143 | assert box_model == BoxModel(Fraction(54), Fraction(8), Spacing(1, 2, 3, 4)) |
| 144 | |
| 145 | |
| 146 | async def test_max(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…