當前位置: 首頁>>代碼示例>>Python>>正文


Python signals.Signal類代碼示例

本文整理匯總了Python中aiohttp.signals.Signal的典型用法代碼示例。如果您正苦於以下問題:Python Signal類的具體用法?Python Signal怎麽用?Python Signal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Signal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_delitem

def test_delitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert len(signal) == 1
    del signal[0]
    assert len(signal) == 0
開發者ID:Eyepea,項目名稱:aiohttp,代碼行數:7,代碼來源:test_signals.py

示例2: test_setitem

def test_setitem(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    assert signal[0] is m1
    m2 = mock.Mock()
    signal[0] = m2
    assert signal[0] is m2
開發者ID:Eyepea,項目名稱:aiohttp,代碼行數:8,代碼來源:test_signals.py

示例3: test_cannot_delitem_in_frozen_signal

def test_cannot_delitem_in_frozen_signal(app):
    signal = Signal(app)
    m1 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        del signal[0]

    assert list(signal) == [m1]
開發者ID:Eyepea,項目名稱:aiohttp,代碼行數:9,代碼來源:test_signals.py

示例4: test_sort_forbidden

def test_sort_forbidden(app):
    l1 = lambda: None
    l2 = lambda: None
    l3 = lambda: None
    signal = Signal(app)
    signal.extend([l1, l2, l3])
    with pytest.raises(NotImplementedError):
        signal.sort()
    assert signal == [l1, l2, l3]
開發者ID:rim99,項目名稱:aiohttp,代碼行數:9,代碼來源:test_signals.py

示例5: test_repr

async def test_repr(app) -> None:
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    assert re.match(r"<Signal owner=<Application .+>, frozen=False, "
                    r"\[<Mock id='\d+'>\]>",
                    repr(signal))
開發者ID:KazuCocoa,項目名稱:aiohttp,代碼行數:10,代碼來源:test_signals.py

示例6: test_cannot_setitem_in_frozen_signal

def test_cannot_setitem_in_frozen_signal(app) -> None:
    signal = Signal(app)
    m1 = mock.Mock()
    m2 = mock.Mock()
    signal.append(m1)
    signal.freeze()
    with pytest.raises(RuntimeError):
        signal[0] = m2

    assert list(signal) == [m1]
開發者ID:KazuCocoa,項目名稱:aiohttp,代碼行數:10,代碼來源:test_signals.py

示例7: test_non_coroutine

def test_non_coroutine(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)

    yield from signal.send(**kwargs)
    callback.assert_called_once_with(**kwargs)
開發者ID:Eyepea,項目名稱:aiohttp,代碼行數:10,代碼來源:test_signals.py

示例8: test_non_coroutine

def test_non_coroutine(loop, app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)

    loop.run_until_complete(signal.send(**kwargs))
    callback.assert_called_once_with(**kwargs)
開發者ID:rim99,項目名稱:aiohttp,代碼行數:10,代碼來源:test_signals.py

示例9: test_non_coroutine

async def test_non_coroutine(app) -> None:
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback = mock.Mock()

    signal.append(callback)
    signal.freeze()

    with pytest.raises(TypeError):
        await signal.send(**kwargs)
開發者ID:KazuCocoa,項目名稱:aiohttp,代碼行數:11,代碼來源:test_signals.py

示例10: test_cannot_send_non_frozen_signal

async def test_cannot_send_non_frozen_signal(app) -> None:
    signal = Signal(app)

    callback = make_mocked_coro()

    signal.append(callback)

    with pytest.raises(RuntimeError):
        await signal.send()

    assert not callback.called
開發者ID:KazuCocoa,項目名稱:aiohttp,代碼行數:11,代碼來源:test_signals.py

示例11: test_function_signal_dispatch

def test_function_signal_dispatch(app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)

    yield from signal.send(**kwargs)
    callback_mock.assert_called_once_with(**kwargs)
開發者ID:Eyepea,項目名稱:aiohttp,代碼行數:14,代碼來源:test_signals.py

示例12: test_function_signal_dispatch

async def test_function_signal_dispatch(app) -> None:
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    async def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)
    signal.freeze()

    await signal.send(**kwargs)
    callback_mock.assert_called_once_with(**kwargs)
開發者ID:KazuCocoa,項目名稱:aiohttp,代碼行數:14,代碼來源:test_signals.py

示例13: test_function_signal_dispatch

def test_function_signal_dispatch(loop, app):
    signal = Signal(app)
    kwargs = {'foo': 1, 'bar': 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(**kwargs):
        callback_mock(**kwargs)

    signal.append(callback)

    loop.run_until_complete(signal.send(**kwargs))
    callback_mock.assert_called_once_with(**kwargs)
開發者ID:rim99,項目名稱:aiohttp,代碼行數:14,代碼來源:test_signals.py

示例14: test_function_signal_dispatch2

def test_function_signal_dispatch2(loop, app):
    signal = Signal(app)
    args = {"a", "b"}
    kwargs = {"foo": 1, "bar": 2}

    callback_mock = mock.Mock()

    @asyncio.coroutine
    def callback(*args, **kwargs):
        callback_mock(*args, **kwargs)

    signal.append(callback)

    loop.run_until_complete(signal.send(*args, **kwargs))
    callback_mock.assert_called_once_with(*args, **kwargs)
開發者ID:graingert,項目名稱:aiohttp,代碼行數:15,代碼來源:test_signals.py

示例15: test_sort_forbidden

def test_sort_forbidden(app):
    def l1():
        pass

    def l2():
        pass

    def l3():
        pass

    signal = Signal(app)
    signal.extend([l1, l2, l3])
    with pytest.raises(NotImplementedError):
        signal.sort()
    assert signal == [l1, l2, l3]
開發者ID:AnyMaster,項目名稱:aiohttp,代碼行數:15,代碼來源:test_signals.py


注:本文中的aiohttp.signals.Signal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。