Skip to content

Commit ac68ba5

Browse files
committed
Add integration tests for Align and Margin controls
Introduces new integration tests for Align and Margin controls in Flet, including golden images for macOS. Also refactors sunflower.py to compute seeds in State's __post_init__ method for improved initialization.
1 parent e808545 commit ac68ba5

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed

sdk/python/examples/apps/declarative/sunflower.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class State:
2323
seeds_count: int = MAX_SEEDS // 2
2424
seeds: list[Seed] = field(default_factory=list)
2525

26+
def __post_init__(self):
27+
self.compute_seeds()
28+
2629
def update_seeds_count(self, new_seeds_count: int):
2730
self.seeds_count = new_seeds_count
2831
self.compute_seeds()
@@ -114,7 +117,5 @@ def main(page: ft.Page):
114117
),
115118
)
116119

117-
state.compute_seeds()
118-
119120

120121
ft.run(main)
3.65 KB
Loading
9.09 KB
Loading
7.25 KB
Loading
6.98 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
3+
import flet as ft
4+
import flet.testing as ftt
5+
6+
7+
@pytest.mark.asyncio(loop_scope="module")
8+
async def test_align_inside_stack(flet_app: ftt.FletTestApp, request):
9+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
10+
await flet_app.assert_control_screenshot(
11+
request.node.name,
12+
ft.Stack(
13+
[
14+
ft.Button("A", align=ft.Alignment(0, 0)),
15+
ft.Button("B", align=ft.Alignment(0.9, 0.9)),
16+
ft.Button("C", align=ft.Alignment.BOTTOM_LEFT),
17+
],
18+
width=200,
19+
height=200,
20+
),
21+
)
22+
23+
24+
@pytest.mark.asyncio(loop_scope="module")
25+
async def test_align_inside_container(flet_app: ftt.FletTestApp, request):
26+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
27+
await flet_app.assert_control_screenshot(
28+
request.node.name,
29+
ft.Container(
30+
ft.Button("B", align=ft.Alignment(0.9, 0.9)),
31+
width=200,
32+
height=200,
33+
),
34+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
import flet as ft
4+
import flet.testing as ftt
5+
6+
7+
@pytest.mark.asyncio(loop_scope="module")
8+
async def test_margin_around(flet_app: ftt.FletTestApp, request):
9+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
10+
await flet_app.assert_control_screenshot(
11+
request.node.name,
12+
ft.Button(
13+
"Button with margin",
14+
margin=ft.Margin.all(20),
15+
),
16+
)
17+
18+
19+
@pytest.mark.asyncio(loop_scope="module")
20+
async def test_margin_bottom_right(flet_app: ftt.FletTestApp, request):
21+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
22+
await flet_app.assert_control_screenshot(
23+
request.node.name,
24+
ft.Button(
25+
"Button with margin",
26+
margin=ft.Margin.only(bottom=20, right=20),
27+
),
28+
)

0 commit comments

Comments
 (0)