本文整理汇总了Python中asynctest.call方法的典型用法代码示例。如果您正苦于以下问题:Python asynctest.call方法的具体用法?Python asynctest.call怎么用?Python asynctest.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asynctest
的用法示例。
在下文中一共展示了asynctest.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_watch_timeout_with_resource_version
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_watch_timeout_with_resource_version(self):
fake_resp = CoroutineMock()
fake_resp.content.readline = CoroutineMock()
fake_resp.release = Mock()
fake_resp.content.readline.side_effect = [asyncio.TimeoutError(),
b""]
fake_api = Mock()
fake_api.get_namespaces = CoroutineMock(return_value=fake_resp)
fake_api.get_namespaces.__doc__ = ':return: V1NamespaceList'
watch = kubernetes_asyncio.watch.Watch()
async with watch.stream(fake_api.get_namespaces, resource_version='10') as stream:
async for e in stream: # noqa
pass
# all calls use the passed resource version
fake_api.get_namespaces.assert_has_calls(
[call(_preload_content=False, watch=True, resource_version='10'),
call(_preload_content=False, watch=True, resource_version='10')])
fake_resp.release.assert_called_once_with()
self.assertEqual(watch.resource_version, '10')
示例2: test_update_callback_is_only_called_when_space_changes
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_update_callback_is_only_called_when_space_changes(self):
self.get_free_space.side_effect = [123, 456] * 2 + [123000, 456]
for i in range(2):
await self.freespace._gather_info_wrapper_coro()
self.assertEqual(self.freespace.info, {
'/foo': SimpleNamespace(path='/foo', free=123, error=None),
'/bar': SimpleNamespace(path='/bar', free=456, error=None)
})
self.assertEqual(self.update_cb.call_args_list, [call(self.freespace)])
await self.freespace._gather_info_wrapper_coro()
self.assertEqual(self.update_cb.call_args_list, [call(self.freespace), call(self.freespace)])
self.assertEqual(self.freespace.info, {
'/foo': SimpleNamespace(path='/foo', free=123000, error=None),
'/bar': SimpleNamespace(path='/bar', free=456, error=None)
})
示例3: test_get_free_space_raises_expected_error
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_get_free_space_raises_expected_error(self):
self.get_free_space.side_effect = (123, ClientError('Nah'))
await self.freespace._gather_info_wrapper_coro()
self.assertEqual(self.freespace.info['/foo'], SimpleNamespace(path='/foo', free=123, error=None))
self.assertEqual(self.freespace.info['/bar'].path, '/bar')
self.assertIs(self.freespace.info['/bar'].free, None)
self.assertEqual(str(self.freespace.info['/bar'].error), 'Nah')
self.assertEqual(self.update_cb.call_args_list, [call(self.freespace)])
self.get_free_space.side_effect = (ClientError('Nah'), 456)
await self.freespace._gather_info_wrapper_coro()
self.assertEqual(self.freespace.info['/foo'].path, '/foo')
self.assertIs(self.freespace.info['/foo'].free, None)
self.assertEqual(str(self.freespace.info['/foo'].error), 'Nah')
self.assertEqual(self.freespace.info['/bar'], SimpleNamespace(path='/bar', free=456, error=None))
self.assertEqual(self.update_cb.call_args_list, [call(self.freespace), call(self.freespace)])
示例4: test_await_args
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_await_args(self):
with self.subTest('in order'):
mock = asynctest.mock.CoroutineMock()
t1 = mock('foo')
t2 = mock('bar')
yield from t1
yield from t2
self.assertEqual(mock.await_args, asynctest.call('bar'))
with self.subTest('out of order'):
mock = asynctest.mock.CoroutineMock()
t1 = mock('foo')
t2 = mock('bar')
yield from t2
yield from t1
self.assertEqual(mock.await_args, asynctest.call('foo'))
示例5: test_await_args_list
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_await_args_list(self):
with self.subTest('in order'):
mock = asynctest.mock.CoroutineMock()
t1 = mock('foo')
t2 = mock('bar')
yield from t1
yield from t2
self.assertEqual(mock.await_args_list, [asynctest.call('foo'), asynctest.call('bar')])
with self.subTest('out of order'):
mock = asynctest.mock.CoroutineMock()
t1 = mock('foo')
t2 = mock('bar')
yield from t2
yield from t1
self.assertEqual(mock.await_args_list, [asynctest.call('bar'), asynctest.call('foo')])
示例6: test_heartbeat
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_heartbeat(self, mock_book, mock_connect):
mock_connect.return_value.aenter.send_json = CoroutineMock()
mock_connect.return_value.aenter.receive_str = CoroutineMock()
mock_book.return_value = {'bids': [], 'asks': [], 'sequence': 1}
message_expected = {
"type": "heartbeat",
"last_trade_id": 17393422,
"product_id": "ETH-USD",
"sequence": 2,
"time": "2017-06-25T11:23:14.838000Z"
}
mock_connect.return_value.aenter.receive_str.side_effect = [
json.dumps(message_expected),
]
product_ids = ['ETH-USD']
async with gdax.orderbook.OrderBook(product_ids,
use_heartbeat=True) as orderbook:
subscribe_msg = {'type': 'subscribe', 'product_ids': product_ids}
heartbeat_msg = {'type': 'heartbeat', 'on': True}
calls = [call(subscribe_msg), call(heartbeat_msg)]
mock_connect.return_value.aenter.send_json.assert_has_calls(calls)
message = await orderbook.handle_message()
assert message == message_expected
示例7: test_run_dispatches_a_new_task_for_each_valid_clock_tick
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_run_dispatches_a_new_task_for_each_valid_clock_tick(self):
clock = asynctest.MagicMock()
clock.__aiter__.return_value = range(3)
wrapped_task = Mock()
with patch.multiple(
self.task_runner,
clock=clock,
_wrapped_task=wrapped_task,
can_dispatch_task=CoroutineMock(side_effect=[True, False, True]),
), patch(
"asyncworker.task_runners.asyncio.ensure_future"
) as ensure_future:
await self.task_runner._run()
self.assertEqual(
ensure_future.call_args_list,
[
call(wrapped_task.return_value),
call(wrapped_task.return_value),
],
)
示例8: test_run_emits_a_task_i_done_event_for_each_valid_clock_tick
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_run_emits_a_task_i_done_event_for_each_valid_clock_tick(
self
):
clock = asynctest.MagicMock()
clock.__aiter__.return_value = range(3)
wrapped_task = Mock()
with patch.multiple(
self.task_runner,
clock=clock,
_wrapped_task=wrapped_task,
task_is_done_event=Mock(),
can_dispatch_task=CoroutineMock(side_effect=[True, False, True]),
), patch(
"asyncworker.task_runners.asyncio.ensure_future"
) as ensure_future:
await self.task_runner._run()
self.task_runner.task_is_done_event.clear.assert_has_calls(
[call(), call()]
)
示例9: test_run_adds_the_new_task_for_each_valid_clock_tick
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_run_adds_the_new_task_for_each_valid_clock_tick(self):
clock = asynctest.MagicMock()
clock.__aiter__.return_value = range(3)
wrapped_task = Mock()
with patch.multiple(
self.task_runner,
clock=clock,
_wrapped_task=wrapped_task,
running_tasks=Mock(spec=set),
can_dispatch_task=CoroutineMock(side_effect=[True, False, True]),
), patch(
"asyncworker.task_runners.asyncio.ensure_future"
) as ensure_future:
await self.task_runner._run()
self.task_runner.running_tasks.add.assert_has_calls(
[
call(ensure_future.return_value),
call(ensure_future.return_value),
]
)
示例10: test_startup_registers_one_connection_per_vhost_into_app_state
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_startup_registers_one_connection_per_vhost_into_app_state(
self, register
):
conn = AMQPConnection(
hostname="127.0.0.1",
username="guest",
password="guest",
prefetch=1024,
)
app = App(connections=[conn])
app.routes_registry = self.routes_registry
await self.signal_handler.startup(app)
self.assertIn(conn, app.connections)
register.assert_has_calls(
[
call(consumer.queue)
for consumer in app[RouteTypes.AMQP_RABBITMQ]["consumers"]
]
)
示例11: test_register_routes_mod_no_version
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_register_routes_mod_no_version(self):
mod_name = "test_mod"
mod = async_mock.MagicMock()
mod.__name__ = mod_name
app = async_mock.MagicMock()
self.registry._plugins[mod_name] = mod
mod.routes.register = async_mock.CoroutineMock()
with async_mock.patch.object(
ClassLoader,
"load_module",
async_mock.MagicMock(side_effect=[None, mod.routes]),
) as load_module:
await self.registry.register_admin_routes(app)
calls = [call("definition", mod_name), call(f"{mod_name}.routes")]
load_module.assert_has_calls(calls)
assert mod.routes.register.call_count == 1
with async_mock.patch.object(
ClassLoader,
"load_module",
async_mock.MagicMock(side_effect=[None, ModuleLoadError()]),
) as load_module:
await self.registry.register_admin_routes(app)
calls = [
call("definition", mod_name),
call(f"{mod_name}.routes"),
]
load_module.assert_has_calls(calls)
assert mod.routes.register.call_count == 1
示例12: test_post_process_routes_mod_no_version
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_post_process_routes_mod_no_version(self):
mod_name = "test_mod"
mod = async_mock.MagicMock()
mod.__name__ = mod_name
app = async_mock.MagicMock()
self.registry._plugins[mod_name] = mod
mod.routes.register = async_mock.CoroutineMock()
with async_mock.patch.object(
ClassLoader,
"load_module",
async_mock.MagicMock(side_effect=[None, mod.routes]),
) as load_module:
self.registry.post_process_routes(app)
calls = [call("definition", mod_name), call(f"{mod_name}.routes")]
load_module.assert_has_calls(calls)
assert mod.routes.post_process_routes.call_count == 1
with async_mock.patch.object(
ClassLoader,
"load_module",
async_mock.MagicMock(side_effect=[None, ModuleLoadError()]),
) as load_module:
self.registry.post_process_routes(app)
calls = [call("definition", mod_name), call(f"{mod_name}.routes")]
load_module.assert_has_calls(calls)
assert mod.routes.post_process_routes.call_count == 1
示例13: test_validate_version_list_correct
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_validate_version_list_correct(self):
mod_name = "test_mod"
mod = async_mock.MagicMock()
mod.__name__ = mod_name
versions = [
{
"major_version": 1,
"minimum_minor_version": 0,
"current_minor_version": 0,
"path": "v1_0",
},
{
"major_version": 2,
"minimum_minor_version": 0,
"current_minor_version": 0,
"path": "v2_0",
},
]
with async_mock.patch.object(
ClassLoader, "load_module", async_mock.MagicMock()
) as load_module:
assert self.registry.validate_version(versions, mod_name) is True
load_module.has_calls(
call(versions[0]["path"], mod_name),
call(versions[1]["path"], mod_name),
)
示例14: test_watch_timeout
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_watch_timeout(self):
fake_resp = CoroutineMock()
fake_resp.content.readline = CoroutineMock()
fake_resp.release = Mock()
mock_event = {"type": "ADDED",
"object": {"metadata": {"name": "test1555",
"resourceVersion": "1555"},
"spec": {},
"status": {}}}
fake_resp.content.readline.side_effect = [json.dumps(mock_event).encode('utf8'),
asyncio.TimeoutError(),
b""]
fake_api = Mock()
fake_api.get_namespaces = CoroutineMock(return_value=fake_resp)
fake_api.get_namespaces.__doc__ = ':return: V1NamespaceList'
watch = kubernetes_asyncio.watch.Watch()
async with watch.stream(fake_api.get_namespaces) as stream:
async for e in stream: # noqa
pass
fake_api.get_namespaces.assert_has_calls(
[call(_preload_content=False, watch=True),
call(_preload_content=False, watch=True, resource_version='1555')])
fake_resp.release.assert_called_once_with()
示例15: test_init_with_default_handlers_initializes_handlers_for_stdout_and_stderr
# 需要导入模块: import asynctest [as 别名]
# 或者: from asynctest import call [as 别名]
def test_init_with_default_handlers_initializes_handlers_for_stdout_and_stderr(
self
):
handlers = [Mock(), Mock()]
with asynctest.patch(
"aiologger.logger.AsyncStreamHandler", side_effect=handlers
) as handler_init:
logger = Logger.with_default_handlers(loop=self.loop)
self.assertCountEqual(logger.handlers, handlers)
self.assertCountEqual(
[LogLevel.DEBUG, LogLevel.WARNING],
[call[1]["level"] for call in handler_init.call_args_list],
)