Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip EDID test if there's no desktop session running (BugFix) #1404

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions providers/base/bin/desktop_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# All rights reserved.
#
# Written by:
# Paolo Gentili <paolo.gentili@canonical.com>

import argparse
import os


def resources():
"""
Return whether there's a Desktop session and its type.
"""
is_desktop_session = os.getenv("XDG_CURRENT_DESKTOP") is not None
print("desktop_session: {}".format(is_desktop_session))
print("session_type: {}".format(os.getenv("XDG_SESSION_TYPE")))


def main(argv):
"""
Retrieve information about the current desktop session.
"""

parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["resources"])
args = parser.parse_args(argv)

if args.command == "resources":
return resources()


if __name__ == "__main__":
import sys

main(sys.argv[1:])
55 changes: 55 additions & 0 deletions providers/base/tests/test_desktop_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""This module provides test cases for the desktop_session module."""

import os
import unittest
from unittest.mock import call, patch

import desktop_session


class DesktopSessionTests(unittest.TestCase):
"""Tests for the desktop_session module."""

@patch("desktop_session.resources")
def test_main(self, mock_resources):
"""
Test whether the main function calls the resources
function when requested via CLI.
"""
desktop_session.main(["resources"])
mock_resources.assert_called_once_with()

@patch("builtins.print")
def test_resources_server(self, mock_print):
"""Test the result faking a server session."""

server_session = {
"XDG_SESSION_TYPE": "tty",
}
with patch.dict(os.environ, server_session, clear=True):
desktop_session.resources()

mock_print.assert_has_calls(
[
call("desktop_session: False"),
call("session_type: tty"),
]
)

@patch("builtins.print")
def test_resources_desktop(self, mock_print):
"""Test the result faking a desktop session."""

server_session = {
"XDG_SESSION_TYPE": "wayland",
"XDG_CURRENT_DESKTOP": "hyprland",
}
with patch.dict(os.environ, server_session, clear=True):
desktop_session.resources()

mock_print.assert_has_calls(
[
call("desktop_session: True"),
call("session_type: wayland"),
]
)
6 changes: 6 additions & 0 deletions providers/base/units/desktop/resource.pxu
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id: desktop_session
plugin: resource
category_id: com.canonical.plainbox::info
_summary: Check whether a desktop session is available and of which type.
environ: XDG_SESSION_TYPE XDG_CURRENT_DESKTOP
command: desktop_session.py resources
7 changes: 6 additions & 1 deletion providers/base/units/zapper/jobs.pxu
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
id: monitor/zapper-edid
requires: zapper_capabilities.capability == 'hdmi-capture' and zapper_capabilities.edid_cycling == 'True'
template-resource: zapper_capabilities desktop_session
requires:
zapper_capabilities.capability == 'hdmi-capture'
zapper_capabilities.edid_cycling == 'True'
desktop_session.desktop_session == 'True'
desktop_session.session_type in ['x11', 'wayland']
category_id: com.canonical.plainbox::monitor
plugin: shell
estimated_duration: 60
Expand Down
2 changes: 1 addition & 1 deletion providers/base/units/zapper/test-plan.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nested_part:

id: zapper-enabled-automated
unit: test plan
_name: Tests using Zapper
_name: Tests using Zapper (automated)
_description: Tests using Zapper
include:
bluetooth/zapper-a2dp
Expand Down
Loading