Skip to content

Commit

Permalink
unify and add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 authored and samschott committed Sep 14, 2024
1 parent e263d9b commit 09a97de
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 60 deletions.
8 changes: 4 additions & 4 deletions testbed/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

# Use this for widgets or tests which are not supported on some platforms, but could be
# supported in the future.
def skip_on_platforms(*platforms):
def skip_on_platforms(*platforms, reason=None):
current_platform = toga.platform.current_platform
if current_platform in platforms:
skip(f"not yet implemented on {current_platform}")
skip(reason or f"not yet implemented on {current_platform}")


# Use this for widgets or tests which are not supported on some platforms, and will not
# be supported in the foreseeable future.
def xfail_on_platforms(*platforms):
def xfail_on_platforms(*platforms, reason=None):
current_platform = toga.platform.current_platform
if current_platform in platforms:
skip(f"not applicable on {current_platform}")
skip(reason or f"not applicable on {current_platform}")


@fixture(autouse=True)
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/widgets/test_activityindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def widget():


async def test_cleanup():
skip_on_platforms("android", "iOS", "windows")
skip_on_platforms("android", "windows")

widget = toga.ActivityIndicator()
ref = weakref.ref(widget)
Expand Down
3 changes: 3 additions & 0 deletions testbed/tests/widgets/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import toga
from toga.style import Pack

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_background_color,
test_background_color_reset,
Expand All @@ -21,6 +22,8 @@ async def widget():


async def test_cleanup():
xfail_on_platforms("iOS", reason="Leaks memory")

widget = toga.Box(style=Pack(width=100, height=200))
ref = weakref.ref(widget)

Expand Down
3 changes: 3 additions & 0 deletions testbed/tests/widgets/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from toga.colors import TRANSPARENT

from ..assertions import assert_color
from ..conftest import xfail_on_platforms
from ..data import TEXTS
from .properties import ( # noqa: F401
test_background_color,
Expand All @@ -34,6 +35,8 @@ async def widget():


async def test_cleanup():
xfail_on_platforms("android", reason="Leaks memory")

widget = toga.Button("Hello")
ref = weakref.ref(widget)

Expand Down
16 changes: 16 additions & 0 deletions testbed/tests/widgets/test_canvas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gc
import math
import os
import weakref
from math import pi, radians
from unittest.mock import Mock, call

Expand All @@ -21,6 +23,7 @@
from toga.fonts import BOLD
from toga.style.pack import SYSTEM, Pack

from ..conftest import skip_on_platforms, xfail_on_platforms
from .properties import ( # noqa: F401
test_background_color,
test_background_color_reset,
Expand Down Expand Up @@ -108,6 +111,19 @@ def assert_pixel(image, x, y, color):
assert image.getpixel((x, y)) == color


async def test_cleanup():
xfail_on_platforms("android", reason="Leaks memory")
skip_on_platforms("macOS", reason="Segfaults on macOS")

widget = toga.Canvas()
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


async def test_resize(widget, probe, on_resize_handler):
"Resizing the widget causes on-resize events"
# Make the canvas visible against window background.
Expand Down
3 changes: 2 additions & 1 deletion testbed/tests/widgets/test_dateinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import toga

from ..conftest import skip_on_platforms
from ..conftest import skip_on_platforms, xfail_on_platforms
from .properties import ( # noqa: F401
test_background_color,
test_background_color_reset,
Expand Down Expand Up @@ -86,6 +86,7 @@ async def widget():

async def test_cleanup():
skip_on_platforms("macOS", "iOS", "linux")
xfail_on_platforms("android", reason="Leaks memory")

widget = toga.DateInput()
ref = weakref.ref(widget)
Expand Down
15 changes: 15 additions & 0 deletions testbed/tests/widgets/test_detailedlist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import gc
import weakref
from unittest.mock import Mock

import pytest
Expand All @@ -6,6 +8,7 @@
from toga.sources import ListSource
from toga.style.pack import Pack

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_enable_noop,
test_flex_widget_size,
Expand Down Expand Up @@ -74,6 +77,18 @@ async def widget(
)


async def test_cleanup():
xfail_on_platforms("android", "linux", reason="Leaks memory")

widget = toga.DetailedList()
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


async def test_scroll(widget, probe):
"""The detailedList can be scrolled"""

Expand Down
3 changes: 2 additions & 1 deletion testbed/tests/widgets/test_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from toga.constants import Direction
from toga.style.pack import COLUMN, ROW

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_enable_noop,
test_focus_noop,
Expand All @@ -19,7 +20,7 @@ async def widget():


async def test_cleanup():
skip_on_platforms("android", "iOS")
xfail_on_platforms("iOS", reason="Leaks memory")

widget = toga.Divider()
ref = weakref.ref(widget)
Expand Down
12 changes: 12 additions & 0 deletions testbed/tests/widgets/test_mapview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import gc
import platform
import weakref
from time import time
from unittest.mock import Mock

Expand Down Expand Up @@ -57,6 +59,16 @@ async def widget(on_select):
toga.App.app._gc_protector.append(widget)


async def test_cleanup():
widget = toga.MapView()
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


# The next two tests fail about 75% of the time in the macOS x86_64 CI configuration.
# The failure mode appears to be that the widget *exists*, but doesn't respond to
# changes in location or zoom. I've been unable to reproduce this in actual testing on
Expand Down
15 changes: 9 additions & 6 deletions testbed/tests/widgets/test_multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import toga
from toga.style import Pack

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_alignment,
test_background_color,
Expand Down Expand Up @@ -39,7 +40,15 @@ async def widget():
return toga.MultilineTextInput(value="Hello", style=Pack(flex=1))


@pytest.fixture
def verify_font_sizes():
# We can't verify font sizes inside the MultilineTextInput
return False, False


async def test_cleanup():
xfail_on_platforms("android", "linux", reason="Leaks memory")

widget = toga.MultilineTextInput(value="Hello")
ref = weakref.ref(widget)

Expand All @@ -49,12 +58,6 @@ async def test_cleanup():
assert ref() is None


@pytest.fixture
def verify_font_sizes():
# We can't verify font sizes inside the MultilineTextInput
return False, False


async def test_scroll_position(widget, probe):
"The widget can be programmatically scrolled."
# The document initially fits within the visible area.
Expand Down
24 changes: 13 additions & 11 deletions testbed/tests/widgets/test_numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import toga

from ..conftest import skip_on_platforms
from ..conftest import skip_on_platforms, xfail_on_platforms
from .properties import ( # noqa: F401
test_alignment,
test_background_color,
Expand All @@ -32,16 +32,6 @@ async def widget():
return toga.NumberInput(value="1.23", step="0.01")


async def test_cleanup():
widget = toga.NumberInput(value="1.23", step="0.01")
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


@pytest.fixture
def verify_font_sizes():
# We can't verify font width inside the TextInput
Expand All @@ -53,6 +43,18 @@ def verify_focus_handlers():
return False


async def test_cleanup():
xfail_on_platforms("android", reason="Leaks memory")

widget = toga.NumberInput(value="1.23", step="0.01")
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


async def test_on_change_handler(widget, probe):
"The on_change handler is triggered when the user types."
widget.step = "0.01"
Expand Down
3 changes: 3 additions & 0 deletions testbed/tests/widgets/test_optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from toga.colors import CORNFLOWERBLUE, GOLDENROD, REBECCAPURPLE, SEAGREEN
from toga.style.pack import Pack

from ..conftest import xfail_on_platforms
from .probe import get_probe
from .properties import ( # noqa: F401
test_enable_noop,
Expand Down Expand Up @@ -74,6 +75,8 @@ async def widget(content1, content2, content3, on_select_handler):


async def test_cleanup():
xfail_on_platforms("android", "iOS", "linux", reason="Leaks memory")

widget = toga.OptionContainer(content=[("Tab 1", toga.Box())])
ref = weakref.ref(widget)

Expand Down
15 changes: 9 additions & 6 deletions testbed/tests/widgets/test_passwordinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import toga

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_alignment,
test_background_color,
Expand Down Expand Up @@ -41,7 +42,15 @@ async def widget():
return toga.PasswordInput(value="sekrit")


@pytest.fixture
def verify_font_sizes():
# We can't verify font width inside the TextInput
return False, True


async def test_cleanup():
xfail_on_platforms("android", reason="Leaks memory")

widget = toga.PasswordInput(value="sekrit")
ref = weakref.ref(widget)

Expand All @@ -51,12 +60,6 @@ async def test_cleanup():
assert ref() is None


@pytest.fixture
def verify_font_sizes():
# We can't verify font width inside the TextInput
return False, True


async def test_value_hidden(widget, probe):
"Value should always be hidden in a PasswordInput"
assert probe.value_hidden
Expand Down
3 changes: 3 additions & 0 deletions testbed/tests/widgets/test_scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from toga.colors import CORNFLOWERBLUE, REBECCAPURPLE, TRANSPARENT
from toga.style.pack import COLUMN, ROW, Pack

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_background_color,
test_background_color_reset,
Expand Down Expand Up @@ -75,6 +76,8 @@ async def widget(content, on_scroll):


async def test_cleanup():
xfail_on_platforms("android", "iOS", "linux", reason="Leaks memory")

widget = toga.ScrollContainer(content=toga.Box())
ref = weakref.ref(widget)

Expand Down
23 changes: 13 additions & 10 deletions testbed/tests/widgets/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from toga.constants import CENTER
from toga.sources import ListSource

from ..conftest import xfail_on_platforms
from .properties import ( # noqa: F401
test_alignment,
test_background_color,
Expand Down Expand Up @@ -42,16 +43,6 @@ async def widget():
return toga.Selection(items=["first", "second", "third"])


async def test_cleanup():
widget = toga.Selection(items=["first", "second", "third"])
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


@pytest.fixture
def verify_font_sizes():
# Font size does not affect the width of this widget.
Expand All @@ -63,6 +54,18 @@ def verify_vertical_alignment():
return CENTER


async def test_cleanup():
xfail_on_platforms("android", "iOS", "windows", reason="Leaks memory")

widget = toga.Selection(items=["first", "second", "third"])
ref = weakref.ref(widget)

del widget
gc.collect()

assert ref() is None


async def test_item_titles(widget, probe):
"""The selection is able to build display titles from a range of data types"""
on_change_handler = Mock()
Expand Down
Loading

0 comments on commit 09a97de

Please sign in to comment.