From 91cbf23d3acc3e44b333cac95d45575bc7bacb1c Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Mon, 3 Jan 2022 18:49:09 +0100 Subject: Added basic event notification capabilities, first event --- notifier_unittest.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 notifier_unittest.py (limited to 'notifier_unittest.py') diff --git a/notifier_unittest.py b/notifier_unittest.py new file mode 100644 index 0000000..721a5fd --- /dev/null +++ b/notifier_unittest.py @@ -0,0 +1,32 @@ +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 + -- cgit v1.2.3