1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <mail@3v1n0.net>
Date: Mon, 1 Sep 2025 03:43:23 +0200
Subject: tests/gio: Check if platform-specific types are exposed in Gio
namespace
---
tests/test_gio.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 86 insertions(+), 1 deletion(-)
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 07ee506..cf1d09d 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -1,14 +1,19 @@
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
+import contextlib
import os
import unittest
import warnings
import pytest
+GioUnix = None
+with contextlib.suppress(ImportError):
+ from gi.repository import GioUnix
+
import gi.overrides
-from gi import PyGIWarning
+from gi import PyGIWarning, PyGIDeprecationWarning
from gi.repository import GLib, Gio
from .helper import ignore_gi_deprecation_warnings
@@ -54,6 +59,86 @@ class TestGio(unittest.TestCase):
'.*Gio\\.VolumeMonitor\\.get\\(\\).*')
+class TestGioPlatform(unittest.TestCase):
+ desktopFileContent = f"""[Desktop Entry]
+Version=1.0
+Type=Application
+Name=Some Application
+Exec={GLib.find_program_in_path("sh")}
+"""
+
+ def setUp(self):
+ super().setUp()
+
+ required_glib = GLib.MAJOR_VERSION > 2 or (
+ GLib.MAJOR_VERSION == 2
+ and (
+ GLib.MINOR_VERSION > 85
+ or (GLib.MINOR_VERSION == 85 and GLib.MICRO_VERSION >= 5)
+ )
+ )
+
+ if not required_glib:
+ self.skipTest("Installed Gio is not new enough for this test")
+
+ if GioUnix:
+ self.key_file = GLib.KeyFile()
+ self.key_file.load_from_data(
+ self.desktopFileContent,
+ len(self.desktopFileContent),
+ GLib.KeyFileFlags.NONE,
+ )
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ def test_desktop_app_info_can_be_created_from_gio_unix(self):
+ app_info = GioUnix.DesktopAppInfo.new_from_keyfile(self.key_file)
+ self.assertIsNotNone(app_info)
+ self.assertIsInstance(app_info, GioUnix.DesktopAppInfo)
+ self.assertIsInstance(app_info, Gio.AppInfo)
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ def test_desktop_app_info_can_be_created_from_gio(self):
+ with warnings.catch_warnings(record=True) as warn:
+ warnings.simplefilter("always")
+ app_info = Gio.DesktopAppInfo.new_from_keyfile(self.key_file)
+
+ self.assertEqual(len(warn), 1)
+ self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning))
+ self.assertEqual(
+ str(warn[0].message),
+ "Gio.DesktopAppInfo is deprecated; "
+ + "use GioUnix.DesktopAppInfo instead",
+ )
+
+ self.assertIsNotNone(app_info)
+ self.assertIsInstance(app_info, Gio.DesktopAppInfo)
+ self.assertIsInstance(app_info, Gio.AppInfo)
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ def test_gio_unix_desktop_app_info_provides_platform_independent_functions(self):
+ app_info = GioUnix.DesktopAppInfo.new_from_keyfile(self.key_file)
+ self.assertEqual(app_info.get_name(), "Some Application")
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ @ignore_gi_deprecation_warnings
+ def test_gio_desktop_app_info_provides_platform_independent_functions(self):
+ app_info = Gio.DesktopAppInfo.new_from_keyfile(self.key_file)
+ self.assertEqual(app_info.get_name(), "Some Application")
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ def test_gio_unix_desktop_app_info_provides_unix_only_functions(self):
+ app_info = GioUnix.DesktopAppInfo.new_from_keyfile(self.key_file)
+ self.assertTrue(app_info.has_key("Name"))
+ self.assertEqual(app_info.get_string("Name"), "Some Application")
+
+ @unittest.skipIf(GioUnix is None, "Not supported")
+ @ignore_gi_deprecation_warnings
+ def test_gio_desktop_app_info_provides_unix_only_functions(self):
+ app_info = Gio.DesktopAppInfo.new_from_keyfile(self.key_file)
+ self.assertTrue(app_info.has_key("Name"))
+ self.assertEqual(app_info.get_string("Name"), "Some Application")
+
+
class TestGSettings(unittest.TestCase):
def setUp(self):
self.settings = Gio.Settings.new('org.gnome.test')
|