diff --git a/lib/logitech_receiver/desktop_notifications.py b/lib/logitech_receiver/desktop_notifications.py index a9cf767625..dfe86ec67d 100644 --- a/lib/logitech_receiver/desktop_notifications.py +++ b/lib/logitech_receiver/desktop_notifications.py @@ -86,7 +86,7 @@ def show(dev, message: str, icon=None): n.set_urgency(Notify.Urgency.NORMAL) n.set_hint("desktop-entry", GLib.Variant("s", "solaar")) # replace with better name late try: - n.show() + return n.show() except Exception: logger.exception(f"showing {n}") diff --git a/lib/solaar/ui/desktop_notifications.py b/lib/solaar/ui/desktop_notifications.py index dcc90d0afb..5843f99ffc 100644 --- a/lib/solaar/ui/desktop_notifications.py +++ b/lib/solaar/ui/desktop_notifications.py @@ -122,7 +122,7 @@ def show(dev, reason=None, icon=None, progress=None): n.set_hint("value", GLib.Variant("i", progress)) try: - n.show() + return n.show() except Exception: logger.exception(f"showing {n}") @@ -139,4 +139,5 @@ def alert(reason): return None def show(dev, reason=None): + return 1000 return None diff --git a/tests/logitech_receiver/test_desktop_notifications.py b/tests/logitech_receiver/test_desktop_notifications.py index 341f204ecd..22905862f9 100644 --- a/tests/logitech_receiver/test_desktop_notifications.py +++ b/tests/logitech_receiver/test_desktop_notifications.py @@ -2,22 +2,28 @@ from logitech_receiver import desktop_notifications - -def test_notifications_available(): - result = desktop_notifications.notifications_available() - - assert not result +# depends on external environment, so make some tests dependent on availability def test_init(): - assert not desktop_notifications.init() + result = desktop_notifications.init() + + assert result == desktop_notifications.available def test_uninit(): assert desktop_notifications.uninit() is None +class MockDevice(mock.Mock): + name = "MockDevice" + + def close(): + return True + + def test_show(): - dev = mock.MagicMock() + dev = MockDevice() reason = "unknown" - assert desktop_notifications.show(dev, reason) is None + result = desktop_notifications.show(dev, reason) + assert result is not None if desktop_notifications.available else result is None diff --git a/tests/solaar/ui/test_desktop_notifications.py b/tests/solaar/ui/test_desktop_notifications.py index f97c215387..342e48c399 100644 --- a/tests/solaar/ui/test_desktop_notifications.py +++ b/tests/solaar/ui/test_desktop_notifications.py @@ -2,15 +2,13 @@ from solaar.ui import desktop_notifications - -def test_notifications_available(): - result = desktop_notifications.notifications_available() - - assert not result +# depends on external environment, so make some tests dependent on availability def test_init(): - assert not desktop_notifications.init() + result = desktop_notifications.init() + + assert result == desktop_notifications.available def test_uninit(): @@ -22,7 +20,17 @@ def test_alert(): assert desktop_notifications.alert(reason) is None +class MockDevice(mock.Mock): + name = "MockDevice" + + def close(): + return True + + def test_show(): - dev = mock.MagicMock() + dev = MockDevice() reason = "unknown" - assert desktop_notifications.show(dev, reason) is None + available = desktop_notifications.init() + + result = desktop_notifications.show(dev, reason) + assert result is not None if available else result is None