def test_delitem(app): signal = Signal(app) m1 = mock.Mock() signal.append(m1) assert len(signal) == 1 del signal[0] assert len(signal) == 0
def function2805(function1121): var1658 = Signal(function1121) var921 = mock.Mock() var1658.append(var921) assert (len(var1658) == 1) del var1658[0] assert (len(var1658) == 0)
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
def function1396(function1121): var3642 = Signal(function1121) var1856 = mock.Mock() var3642.append(var1856) assert (var3642[0] is var1856) var259 = mock.Mock() var3642[0] = var259 assert (var3642[0] is var259)
async def test_repr(app: Any) -> None: signal = Signal(app) callback = make_mocked_coro() signal.append(callback) assert Matches(r"<Signal owner=<Application .+>, frozen=False, " r"\[<Mock id='\d+'>\]>") == repr(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]
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)
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))
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]
async def test_repr(app): 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))
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)
def function1362(function1121): var676 = Signal(function1121) var2961 = { 'foo': 1, 'bar': 2, } function382 = mock.Mock() var676.append(function382) yield from var676.send(None=var2961) function382.assert_called_once_with(None=var2961)
async def test_non_coroutine(app): signal = Signal(app) kwargs = {'foo': 1, 'bar': 2} callback = mock.Mock() signal.append(callback) await signal.send(**kwargs) callback.assert_called_once_with(**kwargs)
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
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)
async def test_cannot_send_non_frozen_signal(app): signal = Signal(app) callback = make_mocked_coro() signal.append(callback) with pytest.raises(RuntimeError): await signal.send() assert not callback.called
def function1281(function2688): assert function2688.debug, 'Should be True' var3888 = Signal(function2688) function382 = mock.Mock() var3839 = mock.Mock() var835 = mock.Mock() var3888.append(function382) function2688.on_pre_signal.append(var3839) function2688.on_post_signal.append(var835) yield from var3888.send(1, a=2) function382.assert_called_once_with(1, a=2) var3839.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2) var835.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
async def test_function_signal_dispatch(app): signal = Signal(app) kwargs = {'foo': 1, 'bar': 2} callback_mock = mock.Mock() async def callback(**kwargs): callback_mock(**kwargs) signal.append(callback) await signal.send(**kwargs) callback_mock.assert_called_once_with(**kwargs)
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)
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)
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)
async def test_function_signal_dispatch2(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) await signal.send(*args, **kwargs) callback_mock.assert_called_once_with(*args, **kwargs)
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)
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]
def function105(function1121): var3164 = Signal(function1121) var96 = { 'foo': 1, 'bar': 2, } var2570 = mock.Mock() @asyncio.coroutine def function382(**kwargs): var2570(None=var96) var3164.append(function382) yield from var3164.send(None=var96) var2570.assert_called_once_with(None=var96)
async def test_debug_signal(debug_app): assert debug_app.debug, "Should be True" signal = Signal(debug_app) callback = mock.Mock() pre = mock.Mock() post = mock.Mock() signal.append(callback) debug_app.on_pre_signal.append(pre) debug_app.on_post_signal.append(post) await signal.send(1, a=2) callback.assert_called_once_with(1, a=2) pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2) post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
def make_request(self, method, path, query_params={}, headers=None, match_info=None): if query_params: path = '%s?%s' % (path, urllib.parse.urlencode(query_params)) # Ported from: # https://github.com/KeepSafe/aiohttp/blob/fa06acc2392c516491bdb25301ad3ef2b700ff5f/tests/test_web_websocket.py#L21-L45 # noqa self.app = mock.Mock() self.app._debug = False if headers is None: headers = CIMultiDict({ 'HOST': 'server.example.com', 'UPGRADE': 'websocket', 'CONNECTION': 'Upgrade', 'SEC-WEBSOCKET-KEY': 'dGhlIHNhbXBsZSBub25jZQ==', 'ORIGIN': 'http://example.com', 'SEC-WEBSOCKET-PROTOCOL': 'chat, superchat', 'SEC-WEBSOCKET-VERSION': '13' }) message = make_raw_request_message(method, path, headers) self.payload = mock.Mock() self.transport = mock.Mock() self.reader = mock.Mock() self.writer = mock.Mock() self.app.loop = self.loop self.app.on_response_prepare = Signal(self.app) req = Request(self.app, message, self.payload, self.transport, self.reader, self.writer) req._match_info = match_info return req
def test_debug_signal(loop, debug_app): assert debug_app.debug, "Should be True" signal = Signal(debug_app) callback = mock.Mock() pre = mock.Mock() post = mock.Mock() signal.append(callback) debug_app.on_pre_signal.append(pre) debug_app.on_post_signal.append(post) loop.run_until_complete(signal.send(1, a=2)) callback.assert_called_once_with(1, a=2) pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2) post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
def test_debug_signal(debug_app): assert debug_app.debug, "Should be True" signal = Signal(debug_app) callback = mock.Mock() pre = mock.Mock() post = mock.Mock() signal.append(callback) debug_app.on_pre_signal.append(pre) debug_app.on_post_signal.append(post) yield from signal.send(1, a=2) callback.assert_called_once_with(1, a=2) pre.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2) post.assert_called_once_with(1, 'aiohttp.signals:Signal', 1, a=2)
def function590(function1121): var906 = Signal(function1121) var730 = {'a', 'b'} var1090 = { 'foo': 1, 'bar': 2, } var852 = mock.Mock() @asyncio.coroutine def function382(*args, **kwargs): var852(*var730, None=var1090) var906.append(function382) yield from var906.send(*var730, None=var1090) var852.assert_called_once_with(*var730, None=var1090)
def maker(method, path, headers=CIMultiDict(), *, version=HttpVersion(1, 1), closing=False, sslcontext=None, secure_proxy_ssl_header=None): if version < HttpVersion(1, 1): closing = True app = mock.Mock() app._debug = False app.on_response_prepare = Signal(app) message = RawRequestMessage(method, path, version, headers, [(k.encode('utf-8'), v.encode('utf-8')) for k, v in headers.items()], closing, False) payload = mock.Mock() transport = mock.Mock() def get_extra_info(key): if key == 'sslcontext': return sslcontext else: return None transport.get_extra_info.side_effect = get_extra_info writer = mock.Mock() reader = mock.Mock() req = Request(app, message, payload, transport, reader, writer, secure_proxy_ssl_header=secure_proxy_ssl_header) assert req.app is app assert req.content is payload assert req.transport is transport return req
def function2183(function1121): var4737 = Signal(function1121) var805 = mock.Mock() var3494 = mock.Mock() var4737.append(var805) var4737.freeze() with pytest.raises(RuntimeError): var4737.append(var3494) assert (list(var4737) == [var805])
def test_cannot_append_to_frozen_signal(app): signal = Signal(app) m1 = mock.Mock() m2 = mock.Mock() signal.append(m1) signal.freeze() with pytest.raises(RuntimeError): signal.append(m2) assert list(signal) == [m1]
def __init__(self): self._state = {} self._frozen = False self._on_startup = Signal(self) self._on_shutdown = Signal(self) self._on_cleanup = Signal(self)
def function2296(function1121): var2457 = Signal(function1121) var2367 = mock.Mock() var2457.append(var2367) var2457.freeze() with pytest.raises(RuntimeError): del var2457[0] assert (list(var2457) == [var2367])
def function2559(function1121): var98 = Signal(function1121) var2142 = mock.Mock() var516 = mock.Mock() var98.append(var2142) var98.freeze() with pytest.raises(RuntimeError): var98[0] = var516 assert (list(var98) == [var2142])
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]
def test_cannot_setitem_in_frozen_signal(app: Any) -> 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]
async def test_non_coroutine(app): signal = Signal(app) kwargs = {'foo': 1, 'bar': 2} callback = mock.Mock() signal.append(callback) signal.freeze() with pytest.raises(TypeError): await signal.send(**kwargs)
def test_copy_forbidden(app): signal = Signal(app) with pytest.raises(NotImplementedError): signal.copy()