Skip to content

Commit

Permalink
testing: upgrade desktop notifications tests to take notifications av…
Browse files Browse the repository at this point in the history
…ailability into account
  • Loading branch information
pfps committed Jan 2, 2025
1 parent 382e0b6 commit c2bc360
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/logitech_receiver/desktop_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
3 changes: 2 additions & 1 deletion lib/solaar/ui/desktop_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -139,4 +139,5 @@ def alert(reason):
return None

def show(dev, reason=None):
return 1000
return None
22 changes: 14 additions & 8 deletions tests/logitech_receiver/test_desktop_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 16 additions & 8 deletions tests/solaar/ui/test_desktop_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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

0 comments on commit c2bc360

Please sign in to comment.