-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip EDID test if there's no desktop session running (BugFix) (#1404)
* Add: desktop_session resource * Change: EDID job requires a desktop_session * Fix: test case for main * Fix: zapper automated testplan name
- Loading branch information
Showing
5 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
|
||
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:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters