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

This commit is contained in:
2025-08-17 13:39:20 +02:00
parent 06a7404b6c
commit e99149f668
+29 -23
View File
@@ -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():