def first(): assert glib_loop._running glib_loop.call_soon(second) glib_loop.run() assert glib_loop._running
def test_run_recursion(self, glib_loop): passed = False def first(): assert glib_loop._running glib_loop.call_soon(second) glib_loop.run() assert glib_loop._running def second(): nonlocal passed assert glib_loop._running glib_loop.stop() assert glib_loop._running passed = True assert not glib_loop._running glib_loop.call_soon(first) glib_loop.run() assert not glib_loop._running assert passed
def test_run_forever_recursion(self, glib_loop): def play_it_again_sam(): with pytest.raises(RuntimeError): glib_loop.run_forever() h = glib_loop.call_soon(play_it_again_sam) glib_loop.call_soon(glib_loop.stop) glib_loop.run_forever()
def test_call_soon_priority_order(self, glib_loop): items = [] def handler(i): items.append(i) for i in range(10): glib_loop.call_soon(handler, i) glib_loop.call_soon(glib_loop.stop) glib_loop.run_forever() assert items assert items == sorted(items)
def test_attachment_order(self, glib_loop): def add(handle): glib_loop._context.iteration(True) assert handle not in glib_loop._handlers assert not handle._source.is_destroyed(), "GSource was completed prior to it being in the handlers set." with mock.patch.object(glib_loop, "_handlers", add=add) as _handlers: handle = glib_loop.call_soon(print)
def test_call_soon_priority(self, glib_loop): h = glib_loop.call_soon(lambda: None) assert h._source.get_priority() == GLib.PRIORITY_DEFAULT h.cancel()
def test_call_soon_no_coroutine(self, glib_loop): with pytest.raises(TypeError): glib_loop.call_soon(no_op_coro)
def coro(): glib_loop.call_soon(glib_loop.stop) yield from asyncio.sleep(5)
def test_call_soon_no_coroutine(self, glib_loop): async def coro(): pass with pytest.raises(TypeError): glib_loop.call_soon(coro)