From e99149f66842c5be27d1e73f3a10d720dfd37388 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Sun, 17 Aug 2025 13:39:20 +0200 Subject: [PATCH] Update tests/test_utils_dbusnotify.py --- tests/test_utils_dbusnotify.py | 52 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/tests/test_utils_dbusnotify.py b/tests/test_utils_dbusnotify.py index d3fd63c89..93ccc72ea 100644 --- a/tests/test_utils_dbusnotify.py +++ b/tests/test_utils_dbusnotify.py @@ -6,32 +6,38 @@ from dbusmock import DBusTestCase from slic.utils.dbusnotify import * os.environ['DISPLAY'] = ':0' -''' -class TestDBusNotify(DBusTestCase): - """Tests pour DBusNotify en utilisant le mock intégré de python-dbusmock.""" - @classmethod - def setUpClass(cls): - # Démarrer un bus de session isolé pour les tests - cls.start_session_bus() - - # Démarrer le mock automatique du service Notifications - cls.mock = cls.spawn_server( - bus_name='org.freedesktop.Notifications', - object_path='/org/freedesktop/Notifications', - interface='org.freedesktop.Notifications', - system_bus=False - ) -''' +import dbus -class _DBusEnv(DBusTestCase): - pass -@pytest.fixture(scope="session", autouse=True) -def _dbus_session(): - _DBusEnv.start_session_bus() - _DBusEnv.spawn_server_template('notification', {}, stdout=None) - yield +@pytest.fixture +def upower_mock(dbusmock_system): + p_mock = dbusmock_system.spawn_server( + 'org.freedesktop.UPower', + '/org/freedesktop/UPower', + 'org.freedesktop.UPower', + system_bus=True, + stdout=subprocess.PIPE) + + # Get a proxy for the UPower object's Mock interface + dbus_upower_mock = dbus.Interface(dbusmock_system.get_dbus(True).get_object( + 'org.freedesktop.UPower', + '/org/freedesktop/UPower' + ), dbusmock.MOCK_IFACE) + dbus_upower_mock.AddMethod('', 'Suspend', '', '', '') + + yield p_mock + + p_mock.stdout.close() + p_mock.terminate() + p_mock.wait() + + +def test_suspend_on_idle(upower_mock): + # run your program in a way that should trigger one suspend call + + # now check the log that we got one Suspend() call + assert upower_mock.stdout.readline() == b'^[0-9.]+ Suspend$' @pytest.fixture def notifier():