Skip to content

Commit

Permalink
ensure that all widgets are created on the same thread
Browse files Browse the repository at this point in the history
  • Loading branch information
samschott committed Sep 15, 2024
1 parent 9e98e71 commit 9fc08c3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
13 changes: 8 additions & 5 deletions testbed/tests/widgets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@ def verify_vertical_alignment():


def build_cleanup_test(
widget_class, args=None, kwargs=None, skip_platforms=(), xfail_platforms=()
widget_constructor, args=None, kwargs=None, skip_platforms=(), xfail_platforms=()
):
async def test_cleanup():
nonlocal args, kwargs

skip_on_platforms(*skip_platforms)
xfail_on_platforms(*xfail_platforms, reason="Leaks memory")

widget = widget_class(
*(args if args is not None else ()),
**(kwargs if kwargs is not None else {}),
)
if args is None:
args = ()

if kwargs is None:
kwargs = {}

widget = widget_constructor(*args, **kwargs)
ref = weakref.ref(widget)

# Args or kwargs may hold a backref to the widget itself, for example if they
Expand Down
4 changes: 3 additions & 1 deletion testbed/tests/widgets/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ async def widget():
return toga.Box(style=Pack(width=100, height=200))


test_cleanup = build_cleanup_test(toga.Box, xfail_platforms=("iOS",))
test_cleanup = build_cleanup_test(
toga.Box, kwargs={"argument": "test"}, xfail_platforms=("iOS",)
)
5 changes: 3 additions & 2 deletions testbed/tests/widgets/test_optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ async def widget(content1, content2, content3, on_select_handler):


test_cleanup = build_cleanup_test(
toga.OptionContainer,
kwargs={"content": [("Tab 1", toga.Box())]},
# Pass a function here to prevent init of toga.Box() in a different thread than
# toga.OptionContainer. This would raise a runtime error on Windows.
lambda: toga.OptionContainer(content=[("Tab 1", toga.Box())]),
xfail_platforms=("android", "iOS", "linux"),
)

Expand Down
5 changes: 3 additions & 2 deletions testbed/tests/widgets/test_scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ async def widget(content, on_scroll):


test_cleanup = build_cleanup_test(
toga.ScrollContainer,
kwargs={"content": toga.Box()},
# Pass a function here to prevent init of toga.Box() in a different thread than
# toga.ScrollContainer. This would raise a runtime error on Windows.
lambda: toga.ScrollContainer(content=toga.Box()),
xfail_platforms=("android", "iOS", "linux"),
)

Expand Down
5 changes: 3 additions & 2 deletions testbed/tests/widgets/test_splitcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ async def widget(content1, content2):


test_cleanup = build_cleanup_test(
toga.SplitContainer,
kwargs={"content": [toga.Box(), toga.Box()]},
# Pass a function here to prevent init of toga.Box() in a different thread than
# toga.SplitContainer. This would raise a runtime error on Windows.
lambda: toga.SplitContainer(content=[toga.Box(), toga.Box()]),
skip_platforms=("android", "iOS"),
)

Expand Down

0 comments on commit 9fc08c3

Please sign in to comment.