Skip to content

Commit

Permalink
Fix testbed coverage for Wayland on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Jun 21, 2024
1 parent e51310f commit d95b5f6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gtk/src/toga_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ def set_main_window(self, window):

def get_screens(self):
display = Gdk.Display.get_default()
if "WAYLAND_DISPLAY" in os.environ: # pragma: no cover
if "WAYLAND_DISPLAY" in os.environ: # pragma: no-cover-if-linux-x
# `get_primary_monitor()` doesn't work on wayland, so return as it is.
return [
ScreenImpl(native=display.get_monitor(i))
for i in range(display.get_n_monitors())
]
else:
else: # pragma: no-cover-if-linux-wayland
primary_screen = ScreenImpl(display.get_primary_monitor())
screen_list = [primary_screen] + [
ScreenImpl(native=display.get_monitor(i))
Expand Down Expand Up @@ -252,7 +252,7 @@ def show_cursor(self):
# Window control
######################################################################

def get_current_window(self):
def get_current_window(self): # pragma: no-cover-if-linux-wayland
current_window = self.native.get_active_window()._impl
return current_window if current_window.interface.visible else None

Expand Down
4 changes: 2 additions & 2 deletions gtk/src/toga_gtk/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def get_size(self) -> Size:
return Size(geometry.width, geometry.height)

def get_image_data(self):
if "WAYLAND_DISPLAY" in os.environ:
if "WAYLAND_DISPLAY" in os.environ: # pragma: no-cover-if-linux-x
# Not implemented on wayland due to wayland security policies.
self.interface.factory.not_implemented("Screen.get_image_data() on Wayland")
else:
else: # pragma: no-cover-if-linux-wayland
# Only works for Xorg
display = self.native.get_display()
screen = display.get_default_screen()
Expand Down
1 change: 1 addition & 0 deletions testbed/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.0.1"
[project.optional-dependencies]
test = [
"coverage==7.5.3",
"coverage-conditional-plugin == 0.9.0",
# fonttools is only needed by Android, but we need to use
# sys.platform == 'linux' as there's no dependency identifier
# that can target Android exclusively until 3.13 lands.
Expand Down
8 changes: 8 additions & 0 deletions testbed/tests/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def run_tests(app, cov, args, report_coverage, run_slow):
branch=True,
source_pkgs=[toga_backend],
)
cov.set_option("run:plugins", ["coverage_conditional_plugin"])
cov.set_option(
"coverage_conditional_plugin:rules",
{
"no-cover-if-linux-wayland": "os_environ.get('WAYLAND_DISPLAY') != ''",
"no-cover-if-linux-x": "os_environ.get('WAYLAND_DISPLAY', 'not-set') == 'not-set'",
},
)
cov.start()

# Create the test app, starting the test suite as a background task
Expand Down

0 comments on commit d95b5f6

Please sign in to comment.