本文整理汇总了Python中mock.MagicMock.assert_called_once方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.assert_called_once方法的具体用法?Python MagicMock.assert_called_once怎么用?Python MagicMock.assert_called_once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.assert_called_once方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AttachVersionArgumentUnitTests
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
class AttachVersionArgumentUnitTests(SubcommandTestCase):
COLOR = MagicMock()
def setUp(self):
SubcommandTestCase.setUp(self)
color_output_patcher = patch(
'gitflow_easyrelease.subcommand.ColorOutput',
return_value=self.COLOR
)
self.mock_color_output = color_output_patcher.start()
self.addCleanup(color_output_patcher.stop)
self.mock_add = MagicMock()
self.parser = MagicMock(add_argument=self.mock_add)
def test_color_output(self):
self.mock_color_output.assert_not_called()
Subcommand.attach_version_argument(
self.parser,
self.subcommand.version_optional
)
self.mock_color_output.assert_called_once_with()
def test_add_call(self):
self.mock_add.assert_not_called()
Subcommand.attach_version_argument(
self.parser,
self.subcommand.version_optional
)
self.mock_add.assert_called_once()
示例2: test_it_delegates_all_remove_vlan_calls_to_supplied_callback
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_it_delegates_all_remove_vlan_calls_to_supplied_callback(self):
unique_message = 'Unique Result'
remove_vlan_function = MagicMock(side_effect=lambda action: ConnectivitySuccessResponse(action, unique_message))
# Arrange
remove_vlan_action = self._stub_remove_vlan_action(full_address='192.1.3.4/1', full_name='res1/port1', vlan_id='200')
server_request = DriverRequest()
server_request.actions = [remove_vlan_action]
request_json = jsonpickle.encode(DriverRequestSimulation(server_request), unpicklable=False)
# Act
result = apply_connectivity_changes(request=request_json,
logger=self.logger,
add_vlan_action={},
remove_vlan_action= remove_vlan_function)
# Assert
remove_vlan_function.assert_called_once()
response = result.driverResponse
""":type : DriverResponse """
action_results = response.actionResults
""":type : list[ConnectivityActionResult] """
# We validate that the action was delegated by looking for th eunique value we returned
self.assertEqual(action_results[0].infoMessage, unique_message)
开发者ID:QualiSystems,项目名称:cloudshell-networking-core,代码行数:29,代码来源:tests_standard_apply_connectivity.py
示例3: test_correlate_message
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_correlate_message(self):
get_validated_tenant_func = MagicMock()
add_correlation_func = MagicMock()
with patch.object(correlator.TenantIdentification,
'get_validated_tenant', get_validated_tenant_func), \
patch('meniscus.api.correlation.zmq.correlator.'
'add_correlation_info_to_message', add_correlation_func):
zmq._correlate_src_message(self.src_msg)
get_validated_tenant_func.assert_called_once()
add_correlation_func.assert_called_once()
示例4: test_correlate_message
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_correlate_message(self):
syslog_message = self.syslog_message_head.as_dict()
syslog_message["message"] = (self.message_part_1 + self.message_part_2 + self.message_part_3).decode("utf-8")
get_validated_tenant_func = MagicMock()
add_correlation_func = MagicMock()
with patch.object(correlator.TenantIdentification, "get_validated_tenant", get_validated_tenant_func), patch(
"meniscus.api.correlation.syslog.correlator." "add_correlation_info_to_message", add_correlation_func
):
syslog._correlate_syslog_message(syslog_message)
get_validated_tenant_func.assert_called_once()
add_correlation_func.assert_called_once()
示例5: test_get_event_type__mapped
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_get_event_type__mapped(self, mock_mappings):
"""Test where an event mapping of the specified name exists."""
mock_name = MagicMock(spec=str)
mock_return = MagicMock(spec=ht.events.event.HoudiniEvent)
mock_mappings.return_value = {mock_name: mock_return}
result = ht.events.event.HoudiniEventFactory.get_event_type(mock_name)
self.assertEqual(result, mock_return.return_value)
mock_return.assert_called_once()
示例6: test_success_step
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_success_step(self):
entered = MagicMock()
exited = MagicMock()
self.my_task.steps['say_hello'].entered_handler = entered
self.my_task.steps['say_hello'].exited_handler = exited
self.client.succeed_step(EmptyRequest())
self.assertEqual(self.my_task.current_step.name, 'say_hello')
entered.assert_called_once()
self.client.succeed_step(EmptyRequest())
exited.assert_called_once()
示例7: test_trigger_job_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_trigger_job_error(self):
check_call = MagicMock()
check_call.side_effect = subprocess.CalledProcessError(
99, ['launchpadTrigger.py'])
logging_error = MagicMock()
trigger = {'name': 'foo-ci',
'branch': 'lp:foo',
'options': ['--trigger-ci']}
plugin_path = '/iSCSI/jenkins/plugin'
with patch('subprocess.check_call', check_call):
with patch("logging.error", logging_error):
self.jt.trigger_job(plugin_path, trigger, 'lock')
logging_error.assert_called_once()
示例8: testCallsOnMove
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def testCallsOnMove(self):
camera = MagicMock()
cja = CameraJoystickAdapter(None)
cja.set_camera(camera)
on_move = MagicMock()
cja.set_on_move(on_move)
cja._handle_axis(0, -16535)
cja._update_camera()
cja._handle_axis(0, 0)
cja._update_camera()
on_move.assert_called_once()
示例9: test_exit_without_active_connection
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_exit_without_active_connection(executor):
quit_handler = MagicMock()
pgspecial = PGSpecial()
pgspecial.register(quit_handler, '\\q', '\\q', 'Quit pgcli.',
arg_type=NO_QUERY, case_sensitive=True, aliases=(':q',))
with patch.object(executor, "conn", BrokenConnection()):
# we should be able to quit the app, even without active connection
run(executor, "\\q", pgspecial=pgspecial)
quit_handler.assert_called_once()
# an exception should be raised when running a query without active connection
with pytest.raises(psycopg2.InterfaceError):
run(executor, "select 1", pgspecial=pgspecial)
示例10: test_exception_on_broadcast
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_exception_on_broadcast(self):
msg, handler, subscriber = self.get_subscription()
error_handler = MagicMock()
self.hub.subscribe(subscriber, msg, handler)
self.hub.subscribe(subscriber, ErrorMessage, error_handler)
test_exception = Exception("Test")
handler.side_effect = test_exception
msg_instance = msg("Test")
self.hub.broadcast(msg_instance)
error_handler.assert_called_once()
err_msg = error_handler.call_args[0][0]
assert err_msg.tag == "%s" % test_exception
示例11: test_returns_202_for_non_durable_message
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_returns_202_for_non_durable_message(self):
correlate_http_msg_func = MagicMock()
with patch('dreadfort.correlation.correlator.correlate_http_message',
correlate_http_msg_func):
self.simulate_request(
self.test_route,
method='POST',
headers={
'content-type': 'application/json',
MESSAGE_TOKEN: self.token
},
body=jsonutils.dumps(self.message))
correlate_http_msg_func.assert_called_once()
self.assertEquals(falcon.HTTP_202, self.srmock.status)
示例12: AttachBaseArgumentUnitTests
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
class AttachBaseArgumentUnitTests(SubcommandTestCase):
def setUp(self):
SubcommandTestCase.setUp(self)
self.mock_add = MagicMock()
self.parser = MagicMock(add_argument=self.mock_add)
@patch(
'gitflow_easyrelease.subcommand.RepoInfo.get_branches',
return_value=[]
)
def test_add_call(self, mock_branches):
mock_branches.assert_not_called()
self.mock_add.assert_not_called()
Subcommand.attach_base_argument(self.parser)
self.mock_add.assert_called_once()
mock_branches.assert_called_once_with()
示例13: assertUploadFileToRemotePath
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def assertUploadFileToRemotePath(self, remote_path, renaming_to=None,
target_type=None, raising=None):
expected_target = remote_path if renaming_to is None else renaming_to
listing_of_target_type = MagicMock()
listing_of_target_type.path_type = MagicMock(return_value=target_type)
self.client.list_path = MagicMock(return_value=listing_of_target_type)
with TempDirectory() as local_dir:
with open(local_dir.write('file.txt', 'contents'), 'rb') as fd:
if raising is None:
target_path = self.instance.upload_file(fd, remote_path)
self.assertEquals(target_path, expected_target)
self.client.put_file.assert_called_once_with(
fd, expected_target)
else:
self.assertRaises(raising, self.instance.upload_file,
fd, remote_path)
self.client.list_path.assert_called_once_with(remote_path)
listing_of_target_type.assert_called_once()
示例14: test_retry_failure_reduced_set
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_retry_failure_reduced_set(self):
sleep = MagicMock()
self.patch(time, "sleep", sleep)
method = MagicMock()
method.side_effect = [
{"FailedResourcesMap": {"arn:abc": {"ErrorCode": "ThrottlingException"}}},
{"Result": 32},
]
self.assertEqual(
universal_retry(method, ["arn:abc", "arn:def"]), {"Result": 32}
)
sleep.assert_called_once()
self.assertTrue(
method.call_args_list == [
call(ResourceARNList=["arn:abc", "arn:def"]),
call(ResourceARNList=["arn:abc"]),
]
)
示例15: test_vim_client_errback
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_called_once [as 别名]
def test_vim_client_errback(self, connect_mock, host_mock):
callback = MagicMock()
vim_client = VimClient("esx.local", "root", "password",
auto_sync=False, errback=callback)
host_mock.side_effect = vim.fault.NotAuthenticated
vim_client.host_system
callback.assert_called_once()
host_mock.side_effect = vim.fault.HostConnectFault
vim_client.host_system
assert_that(callback.call_count, is_(2))
host_mock.side_effect = vim.fault.InvalidLogin
vim_client.host_system
assert_that(callback.call_count, is_(3))
host_mock.side_effect = AcquireCredentialsException
vim_client.host_system
assert_that(callback.call_count, is_(4))