Update tests/test_utils_dbusnotify.py
Run CI Tests / test (push) Successful in 1m16s

This commit is contained in:
2025-08-17 14:10:05 +02:00
parent c1d65751d1
commit 2fe41fbfb0
+20 -16
View File
@@ -3,7 +3,6 @@ import time
import subprocess
import pytest
import dbusmock
from dbusmock import DBusTestCase
from slic.utils.dbusnotify import convert_dbus_strings
os.environ['DISPLAY'] = ':0'
@@ -22,11 +21,11 @@ class _DBusEnv(DBusTestCase):
@pytest.fixture(scope="session", autouse=True)
def _dbus_session_notifications():
# 1) lancer un bus de session
# 1) Bus de session pour tous les tests
_DBusEnv.start_session_bus()
# 2) démarrer le service Notifications (ARGUMENTS POSITIONNELS)
p_mock = _DBusEnv.spawn_server(
# 2) Démarrer le service Notifications (arguments positionnels)
p_notify = _DBusEnv.spawn_server(
'org.freedesktop.Notifications',
'/org/freedesktop/Notifications',
'org.freedesktop.Notifications',
@@ -34,24 +33,29 @@ def _dbus_session_notifications():
None # stdout
)
# 3) récupérer l'objet via le bus
bus = _DBusEnv.get_dbus(False) # False => session bus
# 3) Récupérer l'objet mock et ajouter les méthodes (code string !)
bus = _DBusEnv.get_dbus(False) # session bus
obj = bus.get_object('org.freedesktop.Notifications',
'/org/freedesktop/Notifications')
mock = dbus.Interface(obj, MOCK_IFACE)
# 4) définir les méthodes minimales
# out='ssss' -> tuple de 4 strings
mock.AddMethod('org.freedesktop.Notifications', 'GetServerInformation',
'', 'ssss', ['pytest-notify', 'pytest-vendor', '1.0', '1.2'])
mock.AddMethod('org.freedesktop.Notifications', 'GetCapabilities',
'', 'as', [['actions', 'body', 'icon', 'sound']])
mock.AddMethod('org.freedesktop.Notifications', 'Notify',
'susssasa{sv}i', 'u', [1])
mock.AddMethod('org.freedesktop.Notifications', 'CloseNotification',
'u', '', [])
'', 'ssss', 'ret = ("pytest-notify","pytest-vendor","1.0","1.2")')
yield
# Pas de teardown nécessaire ici
# out='as' -> liste de strings
mock.AddMethod('org.freedesktop.Notifications', 'GetCapabilities',
'', 'as', 'ret = ["actions","body","icon","sound"]')
# in='susssasa{sv}i', out='u' -> entier
mock.AddMethod('org.freedesktop.Notifications', 'Notify',
'susssasa{sv}i', 'u', 'ret = 1')
# in='u', out='' -> rien
mock.AddMethod('org.freedesktop.Notifications', 'CloseNotification',
'u', '', '')
yield # teardown géré par python-dbusmock
@pytest.fixture