diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-01-04 17:55:00 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-01-04 17:55:00 +0100 |
commit | 2b4323eca801638f0a305ff29afe815a45e103b1 (patch) | |
tree | d130038b86d671d78eb52e56ce8d2b9b3bd16842 /notifier_unittest.py | |
parent | c4cb9a96342568890dcf1e36d02d6180bdb26ac8 (diff) |
Added current value to notification system, fixed Qt hack
Diffstat (limited to 'notifier_unittest.py')
-rw-r--r-- | notifier_unittest.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/notifier_unittest.py b/notifier_unittest.py index 13f2285..4aff8f4 100644 --- a/notifier_unittest.py +++ b/notifier_unittest.py @@ -14,20 +14,24 @@ def uut(mockPlayer): def test_allEvents(uut): def checkEvent(uut, event): callbacks = 2 - calledFlags = [False] * 2 + calledFlags = [False] * callbacks + values = [None] * callbacks def createCallback(i): - def cb(): - nonlocal calledFlags + def cb(value): + nonlocal calledFlags, values calledFlags[i] = True + values[i] = value + return cb for i in range(0, callbacks): uut.registerCallback(event, createCallback(i)) assert not any(calledFlags) - uut.notify(event) + uut.notify(event, 123) assert all(calledFlags) + assert values == [123] * callbacks checkEvent(uut, Notifier.PLAYING_STATE_EVENT) checkEvent(uut, Notifier.PLAYBACK_VOLUME_EVENT) @@ -36,33 +40,39 @@ def test_allEvents(uut): checkEvent(uut, Notifier.CURRENT_AB_EVENT) def test_eventWithoutRegisteredCallbacks(uut): - uut.notify(Notifier.PLAYING_STATE_EVENT) + uut.notify(Notifier.PLAYING_STATE_EVENT, 0) # expect no crash def test_eventsWithMockPlayer(uut, mockPlayer): - def checkEvent(eventCode, simulateEvent): + def checkEvent(eventCode, simulateEvent, expectedValue): called = False - def callback(): - nonlocal called + receivedValue = None + def callback(value): + nonlocal called, receivedValue called = True + receivedValue = value uut.registerCallback(eventCode, callback) assert not called simulateEvent() assert called + assert receivedValue == expectedValue + + mockPlayer.state = 1 + mockPlayer.volume = 75 - checkEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged) - checkEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged) + checkEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged, True) + checkEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged, 75) def test_singleEventNotification(uut): playingStateCalled = False - def playingStateCallback(): + def playingStateCallback(value): nonlocal playingStateCalled playingStateCalled = True volumeCalled = False - def volumeCallback(): + def volumeCallback(value): nonlocal volumeCalled volumeCalled = True @@ -72,18 +82,18 @@ def test_singleEventNotification(uut): assert not playingStateCalled assert not volumeCalled - uut.notify(Notifier.PLAYING_STATE_EVENT) + uut.notify(Notifier.PLAYING_STATE_EVENT, 0) assert playingStateCalled assert not volumeCalled playingStateCalled = False - uut.notify(Notifier.PLAYBACK_VOLUME_EVENT) + uut.notify(Notifier.PLAYBACK_VOLUME_EVENT, 0) assert not playingStateCalled assert volumeCalled volumeCalled = False - uut.notify(Notifier.PLAYBACK_RATE_EVENT) + uut.notify(Notifier.PLAYBACK_RATE_EVENT, 0) assert not playingStateCalled assert not volumeCalled |