From 3eed7537f8cc0221a81951b24ef965f6b7f35d6e Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 4 Jan 2022 14:58:39 +0100 Subject: Added song and AB limits change notification --- notifier_unittest.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'notifier_unittest.py') diff --git a/notifier_unittest.py b/notifier_unittest.py index 9f37992..13f2285 100644 --- a/notifier_unittest.py +++ b/notifier_unittest.py @@ -11,34 +11,36 @@ def mockPlayer(): def uut(mockPlayer): return Notifier(mockPlayer) -def checkEvent(uut, event): - callbacks = 2 - calledFlags = [False] * 2 +def test_allEvents(uut): + def checkEvent(uut, event): + callbacks = 2 + calledFlags = [False] * 2 - def createCallback(i): - def cb(): - nonlocal calledFlags - calledFlags[i] = True - return cb + def createCallback(i): + def cb(): + nonlocal calledFlags + calledFlags[i] = True + return cb - for i in range(0, callbacks): - uut.registerCallback(event, createCallback(i)) + for i in range(0, callbacks): + uut.registerCallback(event, createCallback(i)) - assert not any(calledFlags) - uut.notify(event) - assert all(calledFlags) + assert not any(calledFlags) + uut.notify(event) + assert all(calledFlags) -def test_allEvents(uut): checkEvent(uut, Notifier.PLAYING_STATE_EVENT) checkEvent(uut, Notifier.PLAYBACK_VOLUME_EVENT) checkEvent(uut, Notifier.PLAYBACK_RATE_EVENT) + checkEvent(uut, Notifier.CURRENT_SONG_EVENT) + checkEvent(uut, Notifier.CURRENT_AB_EVENT) def test_eventWithoutRegisteredCallbacks(uut): uut.notify(Notifier.PLAYING_STATE_EVENT) # expect no crash def test_eventsWithMockPlayer(uut, mockPlayer): - def testEvent(eventCode, simulateEvent): + def checkEvent(eventCode, simulateEvent): called = False def callback(): nonlocal called @@ -50,8 +52,8 @@ def test_eventsWithMockPlayer(uut, mockPlayer): simulateEvent() assert called - testEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged) - testEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged) + checkEvent(Notifier.PLAYING_STATE_EVENT, mockPlayer.simulatePlayingStateChanged) + checkEvent(Notifier.PLAYBACK_VOLUME_EVENT, mockPlayer.simulatePlaybackVolumeChanged) def test_singleEventNotification(uut): playingStateCalled = False -- cgit v1.2.3