import pytest from notifier import Notifier @pytest.fixture def uut(): return Notifier() def checkEvent(uut, event): callbacks = 2 calledFlags = [False] * 2 def createCallback(i): def cb(): nonlocal calledFlags calledFlags[i] = True return cb for i in range(0, callbacks): uut.registerCallback(event, createCallback(i)) assert not any(calledFlags) uut.notify(event) assert all(calledFlags) def test_allEvents(uut): checkEvent(uut, Notifier.PLAYING_STATE_EVENT) def test_eventWithoutRegisteredCallbacks(uut): uut.notify(Notifier.PLAYING_STATE_EVENT) # expect no crash