Skip to content

Commit a642103

Browse files
committed
tests: core: properly unregister callback
this is needed for stopping and restarting core
1 parent 40dd51f commit a642103

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

safeeyes/tests/test_core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def timeout_add_seconds(self, duration: int, callback: typing.Callable) -> int:
4747
self.callback = (callback, duration)
4848
return 1
4949

50+
def source_remove(self, source_id: int) -> None:
51+
if self.callback is None:
52+
raise Exception("no callback registered")
53+
self.callback = None
54+
5055
def next(self) -> None:
5156
assert self.callback
5257

@@ -105,7 +110,9 @@ def timeout_add_seconds(duration, callback) -> int:
105110
return handle.timeout_add_seconds(duration, callback)
106111

107112
def source_remove(source_id: int) -> None:
108-
pass
113+
if not handle:
114+
raise Exception("handle must be initialized before first call")
115+
handle.source_remove(source_id)
109116

110117
monkeypatch.setattr(core.GLib, "timeout_add_seconds", timeout_add_seconds)
111118
monkeypatch.setattr(core.GLib, "source_remove", source_remove)

0 commit comments

Comments
 (0)