Added tests for core

This commit is contained in:
proneon267 2024-01-17 11:10:04 -08:00
parent 0d011539fd
commit efe2b699f2
5 changed files with 60 additions and 2 deletions

View file

@ -8,7 +8,7 @@ if sys.version_info >= (3, 10):
else:
# Before Python 3.10, entry_points did not support the group argument;
# so, the backport package must be used on older versions.
from importlib_metadata import entry_points
from importlib_metadata import entry_points # pragma: no cover
# Map python sys.platform with toga platforms names

View file

@ -8,6 +8,8 @@ from unittest.mock import Mock
import pytest
import toga
from toga.screen import Screen as ScreenInterface
from toga_dummy.screen import Screen as ScreenImpl
from toga_dummy.utils import (
assert_action_not_performed,
assert_action_performed,
@ -621,3 +623,10 @@ def test_deprecated_name():
assert app.formal_name == "Test App"
with pytest.warns(DeprecationWarning, match=name_warning):
assert app.name == "Test App"
def test_screens(app):
assert isinstance(app.screens, list)
for screen in app.screens:
assert isinstance(screen, ScreenInterface)
assert isinstance(screen._impl, ScreenImpl)

25
core/tests/test_screen.py Normal file
View file

@ -0,0 +1,25 @@
from toga_dummy.utils import assert_action_performed
def test_name(app):
assert app.screens[0].name == "primary_screen"
assert app.screens[1].name == "secondary_screen"
def test_origin(app):
assert app.screens[0].origin == (0, 0)
assert app.screens[1].origin == (-1920, 0)
def test_size(app):
assert app.screens[0].size == (1920, 1080)
assert app.screens[1].size == (1920, 1080)
# Same as for the window as_image() test.
def test_as_image(app):
"""A screen can be captured as an image"""
image = app.screens[0].as_image()
assert_action_performed(app.screens[0], "get image data")
# Don't need to check the raw data; just check it's the right size.
assert image.size == (318, 346)

View file

@ -4,6 +4,8 @@ from unittest.mock import Mock
import pytest
import toga
from toga.screen import Screen as ScreenInterface
from toga_dummy.screen import Screen as ScreenImpl
from toga_dummy.utils import (
assert_action_not_performed,
assert_action_performed,
@ -354,6 +356,22 @@ def test_as_image(window):
assert image.size == (318, 346)
def test_screen(window, app):
assert isinstance(window.screen, ScreenInterface)
assert isinstance(window.screen._impl, ScreenImpl)
# Cannot actually change window.screen, so just check
# the window positions as a substitute for moving the
# window between the screens.
assert window.position == (100, 100)
window.screen = app.screens[1]
assert window.position == (-1820, 100)
def test_screen_position(window, app):
window.screen_position = (0, 0)
assert window.screen_position == (0, 0)
def test_info_dialog(window, app):
"""An info dialog can be shown"""
on_result_handler = Mock()

View file

@ -1,3 +1,6 @@
from pathlib import Path
import toga_dummy
from toga.screen import Screen as ScreenInterface
from .utils import LoggedObject # noqa
@ -28,5 +31,8 @@ class Screen(LoggedObject):
def get_size(self):
return (1920, 1080)
# Same as for the window as_image().
def get_image_data(self):
self._action("get_image_data")
self._action("get image data")
path = Path(toga_dummy.__file__).parent / "resources/screenshot.png"
return path.read_bytes()