Пример #1
0
        def first():
            assert glib_loop._running

            glib_loop.call_soon(second)
            glib_loop.run()

            assert glib_loop._running
Пример #2
0
        def first():
            assert glib_loop._running

            glib_loop.call_soon(second)
            glib_loop.run()

            assert glib_loop._running
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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()
Пример #6
0
    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()
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
 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()
Пример #11
0
 def test_call_soon_no_coroutine(self, glib_loop):
     with pytest.raises(TypeError):
         glib_loop.call_soon(no_op_coro)
Пример #12
0
 def coro():
     glib_loop.call_soon(glib_loop.stop)
     yield from asyncio.sleep(5)
Пример #13
0
 def coro():
     glib_loop.call_soon(glib_loop.stop)
     yield from asyncio.sleep(5)
Пример #14
0
    def test_call_soon_no_coroutine(self, glib_loop):
        async def coro():
            pass

        with pytest.raises(TypeError):
            glib_loop.call_soon(coro)