This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user