@@ -24,6 +24,7 @@ async def test_implicit_size(widget, probe, container_probe):
2424 assert probe .width == pytest .approx (144 , abs = 2 )
2525 assert probe .height == pytest .approx (72 , abs = 2 )
2626 assert probe .preserve_aspect_ratio
27+ probe .assert_image_size (144 , 72 )
2728
2829 # Clear the image; it's now an explicit sized empty image.
2930 widget .image = None
@@ -34,6 +35,7 @@ async def test_implicit_size(widget, probe, container_probe):
3435 assert not probe .preserve_aspect_ratio
3536
3637 # Restore the image; Make the parent a flex row
38+ # Image will become as wide as the container.
3739 widget .image = "resources/sample.png"
3840 widget .style .flex = 1
3941 widget .parent .style .direction = ROW
@@ -42,25 +44,36 @@ async def test_implicit_size(widget, probe, container_probe):
4244 assert probe .width == pytest .approx (container_probe .width , abs = 2 )
4345 assert probe .height == pytest .approx (container_probe .height , abs = 2 )
4446 assert probe .preserve_aspect_ratio
47+ probe .assert_image_size (
48+ pytest .approx (probe .width , abs = 2 ),
49+ pytest .approx (probe .width // 2 , abs = 2 ),
50+ )
4551
4652 # Make the parent a flex column
53+ # Image will try to be as tall as the container, but will be
54+ # constrained by preserving the aspect ratio
4755 widget .parent .style .direction = COLUMN
4856
4957 await probe .redraw ("Image is in a column box" )
5058 assert probe .width == pytest .approx (container_probe .width , abs = 2 )
5159 assert probe .height == pytest .approx (container_probe .height , abs = 2 )
5260 assert probe .preserve_aspect_ratio
61+ probe .assert_image_size (
62+ pytest .approx (probe .width , abs = 2 ),
63+ pytest .approx (probe .width // 2 , abs = 2 ),
64+ )
5365
5466
5567async def test_explicit_width (widget , probe , container_probe ):
5668 """If the image width is explicit, the image view will resize preserving aspect ratio."""
57- # Explicitly set width
69+ # Explicitly set width; height follows aspect raio
5870 widget .style .width = 200
5971
6072 await probe .redraw ("Image has explicit width" )
6173 assert probe .width == pytest .approx (200 , abs = 2 )
6274 assert probe .height == pytest .approx (100 , abs = 2 )
6375 assert probe .preserve_aspect_ratio
76+ probe .assert_image_size (200 , 100 )
6477
6578 # Clear the image; it's now an explicit sized empty image.
6679 widget .image = None
@@ -79,6 +92,8 @@ async def test_explicit_width(widget, probe, container_probe):
7992 assert probe .width == pytest .approx (200 , abs = 2 )
8093 assert probe .height == pytest .approx (container_probe .height , abs = 2 )
8194 assert probe .preserve_aspect_ratio
95+ # Container has fixed width; aspect ratio is preserved, so image isn't tall
96+ probe .assert_image_size (200 , 100 )
8297
8398 # Make the parent a flex column
8499 widget .parent .style .direction = COLUMN
@@ -87,17 +102,20 @@ async def test_explicit_width(widget, probe, container_probe):
87102 assert probe .width == pytest .approx (200 , abs = 2 )
88103 assert probe .height == pytest .approx (container_probe .height , abs = 2 )
89104 assert probe .preserve_aspect_ratio
105+ # Container has fixed width; aspect ratio is preserved, image is implicit height
106+ probe .assert_image_size (200 , 100 )
90107
91108
92109async def test_explicit_height (widget , probe , container_probe ):
93110 """If the image height is explicit, the image view will resize preserving aspect ratio."""
94- # Explicitly set height
111+ # Explicitly set height; width follows aspect raio
95112 widget .style .height = 150
96113
97114 await probe .redraw ("Image has explicit height" )
98115 assert probe .width == pytest .approx (300 , abs = 2 )
99116 assert probe .height == pytest .approx (150 , abs = 2 )
100117 assert probe .preserve_aspect_ratio
118+ probe .assert_image_size (300 , 150 )
101119
102120 # Clear the image; it's now an explicit sized empty image.
103121 widget .image = None
@@ -116,6 +134,8 @@ async def test_explicit_height(widget, probe, container_probe):
116134 assert probe .width == pytest .approx (container_probe .width , abs = 2 )
117135 assert probe .height == pytest .approx (150 , abs = 2 )
118136 assert probe .preserve_aspect_ratio
137+ # Container has fixed height; aspect ratio is preserved, so image isn't wide
138+ probe .assert_image_size (300 , 150 )
119139
120140 # Make the parent a flex column
121141 widget .parent .style .direction = COLUMN
@@ -124,6 +144,8 @@ async def test_explicit_height(widget, probe, container_probe):
124144 assert probe .width == pytest .approx (container_probe .width , abs = 2 )
125145 assert probe .height == pytest .approx (150 , abs = 2 )
126146 assert probe .preserve_aspect_ratio
147+ # Container has fixed height; aspect ratio is preserved, image is implicit height
148+ probe .assert_image_size (300 , 150 )
127149
128150
129151async def test_explicit_size (widget , probe ):
@@ -136,6 +158,8 @@ async def test_explicit_size(widget, probe):
136158 assert probe .width == pytest .approx (200 , abs = 2 )
137159 assert probe .height == pytest .approx (300 , abs = 2 )
138160 assert not probe .preserve_aspect_ratio
161+ # Image is the size specified.
162+ probe .assert_image_size (200 , 300 )
139163
140164 # Clear the image; it's now an explicit sized empty image.
141165 widget .image = None
@@ -154,6 +178,8 @@ async def test_explicit_size(widget, probe):
154178 assert probe .width == pytest .approx (200 , abs = 2 )
155179 assert probe .height == pytest .approx (300 , abs = 2 )
156180 assert not probe .preserve_aspect_ratio
181+ # Image is the size specified.
182+ probe .assert_image_size (200 , 300 )
157183
158184 # Make the parent a flex column
159185 widget .parent .style .direction = COLUMN
@@ -162,3 +188,5 @@ async def test_explicit_size(widget, probe):
162188 assert probe .width == pytest .approx (200 , abs = 2 )
163189 assert probe .height == pytest .approx (300 , abs = 2 )
164190 assert not probe .preserve_aspect_ratio
191+ # Image is the size specified.
192+ probe .assert_image_size (200 , 300 )
0 commit comments