Exemple #1
0
def test_queue_call(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(
        spec=("run", "queue_call")
    )
    with eventloop.async_context():
        eventloop.queue_call(42, "foo", "bar", baz="qux")
        loop.queue_call.assert_called_once_with(42, "foo", "bar", baz="qux")
Exemple #2
0
def test_add_idle(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(
        spec=("run", "add_idle")
    )
    with eventloop.async_context():
        eventloop.add_idle("foo", "bar", baz="qux")
        loop.add_idle.assert_called_once_with("foo", "bar", baz="qux")
def test_async_context(EventLoop):
    one = unittest.mock.Mock(spec=("run", ))
    two = unittest.mock.Mock(spec=("run", ))
    EventLoop.side_effect = [one, two]
    assert eventloop.contexts.current() is None

    with eventloop.async_context():
        assert eventloop.contexts.current() is one
        one.run.assert_not_called()

        with eventloop.async_context():
            assert eventloop.contexts.current() is two
            two.run.assert_not_called()

        assert eventloop.contexts.current() is one
        one.run.assert_not_called()
        two.run.assert_called_once_with()

    assert eventloop.contexts.current() is None
    one.run.assert_called_once_with()
def test_get_event_loop():
    with pytest.raises(exceptions.AsyncContextError):
        eventloop.get_event_loop()
    with eventloop.async_context():
        assert isinstance(eventloop.get_event_loop(), eventloop.EventLoop)
Exemple #5
0
def test_run1(EventLoop):
    EventLoop.return_value = loop = unittest.mock.Mock(spec=("run", "run1"))
    with eventloop.async_context():
        eventloop.run1()
        loop.run1.assert_called_once_with()