本文整理汇总了Python中mock.MagicMock.reset_mock方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.reset_mock方法的具体用法?Python MagicMock.reset_mock怎么用?Python MagicMock.reset_mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.reset_mock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
class TestRest:
def __init__(self):
self.registry = MagicMock(Registry)
self.client_mediator = MagicMock(ClientMediator)
self.rest = None
def setup(self):
self.client_mediator.reset_mock()
self.rest = RestServer(self.client_mediator)
def test_register_package(self):
self.rest.register_package(TEST_PACKAGE)
self.client_mediator.handle_registration.assert_called_once_with(TEST_PACKAGE, TEST_PACKAGE)
def test_unregister(self):
package = 'Foo'
self.rest.unregister_package(package)
self.client_mediator.handle_unregistration.assert_called_once_with(package)
def test_invoke(self):
service = 'Foo'
method = 'test'
body = {"a": 1}
self.rest.invoke(TEST_PACKAGE, service, method, body)
def test_run(self):
self.rest.run()
bottle.run.assert_called_once()
示例2: test_VERB_methods
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_VERB_methods(self):
link = 'http://sixtyten.org/verby/'
data = dict(up='down', left='right')
c = MagicMock(spec=Session)
r = Resource(c, link)
r.DELETE(timeout=3)
c.request.assert_called_once_with('DELETE', link, timeout=3)
c.reset_mock()
r.GET(timeout=4)
c.request.assert_called_once_with('GET', link, timeout=4)
c.reset_mock()
r.PATCH(data=data, timeout=5)
c.request.assert_called_once_with('PATCH', link, data=data, timeout=5)
c.reset_mock()
r.POST(data=data, timeout=6)
c.request.assert_called_once_with('POST', link, data=data, timeout=6)
c.reset_mock()
r.PUT(data=data, timeout=7)
c.request.assert_called_once_with('PUT', link, data=data, timeout=7)
c.reset_mock()
示例3: test_remove_container
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_remove_container(mockDocker, mockOutput):
"""
Test that the remove_container function does it's job.
"""
update = MagicMock()
update.name = 'test'
container = MagicMock()
client = MagicMock()
client.containers.get.return_value = container
service = MagicMock()
mockDocker.return_value = client
dockerapi.remove_container(update, service)
mockDocker.assert_called_once_with(base_url='unix://var/run/docker.sock', version='auto')
container.remove.assert_called_once_with(force=True)
#client.images.remove.assert_called_once()
assert update.complete.call_count == 0
client.reset_mock()
mockDocker.side_effect = Exception('Test')
try:
dockerapi.remove_container(update, service)
except Exception as e:
assert e.message == 'Test'
示例4: test_resolve_room_categories
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_resolve_room_categories(self):
a_floor = MagicMock()
should_be_called = MagicMock(return_value = True)
cats = MagicMock(return_value = "cats_result")
class_ns = "__main__.DXFRoomCatsResolver"
with patch(class_ns+".get_room_categories_dict", cats):
with patch(class_ns+"._resolve_room_categories_for_floor", should_be_called):
# Chiamata 1 - un solo floor, passato come parametro
r = DXFRoomCatsResolver.resolve_room_categories(MagicMock(), a_floor)
self.assertEqual(r, 1)
MagicMock.assert_called_once_with(cats)
MagicMock.assert_called_once_with(
should_be_called,
a_floor,
"cats_result",
)
MagicMock.reset_mock(should_be_called)
b = {
"dxf": { "floors": ["firstfloor", "secondfloor", "thirdfloor"] }
}
r = DXFRoomCatsResolver.resolve_room_categories(b)
for f in b["dxf"]["floors"]:
MagicMock.assert_any_call(
should_be_called,
f,
"cats_result"
)
self.assertEqual(r, 3)
示例5: test_check_archiver_errors
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_check_archiver_errors(self, isdir_mock, listdir_mock):
server = build_real_server()
check_strategy = MagicMock()
# There is no error file
check_strategy.reset_mock()
listdir_mock.return_value = []
server.check_archiver_errors(check_strategy)
check_strategy.result.assert_called_with("main", "archiver errors", True, None)
# There is one duplicate file
check_strategy.reset_mock()
listdir_mock.return_value = ["testing.duplicate"]
server.check_archiver_errors(check_strategy)
check_strategy.result.assert_called_with("main", "archiver errors", False, "duplicates: 1")
# There is one unknown file
check_strategy.reset_mock()
listdir_mock.return_value = ["testing.unknown"]
server.check_archiver_errors(check_strategy)
check_strategy.result.assert_called_with("main", "archiver errors", False, "unknown: 1")
# There is one not relevant file
check_strategy.reset_mock()
listdir_mock.return_value = ["testing.error"]
server.check_archiver_errors(check_strategy)
check_strategy.result.assert_called_with("main", "archiver errors", False, "not relevant: 1")
# There is one extraneous file
check_strategy.reset_mock()
listdir_mock.return_value = ["testing.wrongextension"]
server.check_archiver_errors(check_strategy)
check_strategy.result.assert_called_with("main", "archiver errors", False, "unknown failure: 1")
示例6: test_handle_lirc_code
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_handle_lirc_code(self):
# Test normal event callback.
self.infrared_sensor.register("start", self.mock_callback)
self.infrared_sensor._handle_lirc_code(None)
self.mock_callback.assert_not_called()
self.infrared_sensor._handle_lirc_code(['start'])
self.mock_callback.assert_called_once_with()
# Test additional release callback.
self.mock_callback.reset_mock()
mock_stop_callback = MagicMock()
mock_stop_release_callback = MagicMock()
self.infrared_sensor.register("stop", mock_stop_callback,
mock_stop_release_callback)
self.infrared_sensor._handle_lirc_code(None)
mock_stop_callback.assert_not_called()
mock_stop_release_callback.assert_not_called()
self.infrared_sensor._handle_lirc_code(['stop'])
mock_stop_callback.assert_called_once_with()
mock_stop_release_callback.assert_not_called()
# The release callback is called once the stop code is not provided.
# The normal callback is not called. Another non-code does not call the
# release callback again.
mock_stop_callback.reset_mock()
self.infrared_sensor._handle_lirc_code(None)
self.infrared_sensor._handle_lirc_code(None)
mock_stop_callback.assert_not_called()
mock_stop_release_callback.assert_called_once_with()
# Start button was not pressed, so its callback is not called.
self.mock_callback.assert_not_called()
示例7: test_ifd
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_ifd(self):
mock_type = MagicMock(spec=hou.NodeType)
mock_type.name.return_value = "ifd"
mock_node = MagicMock(spec=hou.Node)
mock_node.type.return_value = mock_type
# Return True for soho_outputmode (writing ifd) and the path.
mock_node.evalParm.side_effect = (True, "/var/tmp/test.ifd")
result = ht.events.events.rop_render._get_target_file(mock_node)
self.assertEqual(result, "/var/tmp/test.ifd")
mock_node.evalParm.assert_any_call("soho_outputmode")
mock_node.evalParm.assert_any_call("soho_diskfile")
mock_node.reset_mock()
# Try again but with writing an image.
mock_node.evalParm.side_effect = (False, "/var/tmp/test.exr")
result = ht.events.events.rop_render._get_target_file(mock_node)
self.assertEqual(result, "/var/tmp/test.exr")
mock_node.evalParm.assert_any_call("soho_outputmode")
mock_node.evalParm.assert_any_call("vm_picture")
示例8: test_wait_for_providers_task
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_wait_for_providers_task(self, mock_export_run):
mock_run_uid = str(uuid.uuid4())
mock_provider_task = Mock(status=TaskStates.SUCCESS.value)
mock_export_run.objects.filter().first.return_value = Mock()
mock_export_run.objects.filter().first().provider_tasks.filter.return_value = [mock_provider_task]
callback_task = MagicMock()
apply_args = {"arg1": "example_value"}
wait_for_providers_task(run_uid=mock_run_uid, callback_task=callback_task, apply_args=apply_args)
callback_task.apply_async.assert_called_once_with(**apply_args)
callback_task.reset_mock()
mock_provider_task = Mock(status=TaskStates.RUNNING.value)
mock_export_run.objects.filter().first.return_value = Mock()
mock_export_run.objects.filter().first().provider_tasks.filter.return_value = [mock_provider_task]
wait_for_providers_task(run_uid=mock_run_uid, callback_task=callback_task, apply_args=apply_args)
callback_task.apply_async.assert_not_called()
with self.assertRaises(Exception):
mock_export_run.reset_mock()
mock_export_run.objects.filter().first().__nonzero__.return_value = False
wait_for_providers_task(run_uid=mock_run_uid, callback_task=callback_task, apply_args=apply_args)
示例9: test_overwrite_filelocking
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_overwrite_filelocking():
path = 'tests/fixtures/empty_repo.conf'
mocked_path = MagicMock()
mocked_path.__str__ = lambda x: path
mocked_fcntl = MagicMock()
mocked_open = MagicMock()
with patch('pyolite.repo.open', mocked_open, create=True):
manager = mocked_open.return_value.__enter__.return_value
# asserts file locking has been put in place before writing
manager.write = lambda text: ([
mocked_fcntl.flock.assert_called_once_with(
manager, mocked_fcntl.LOCK_EX
),
mocked_fcntl.reset_mock()
])
with patch.multiple('pyolite.repo', fcntl=mocked_fcntl):
repo = Repo(path)
mocked_fcntl.reset_mock()
repo.overwrite('some_text')
# asserts lock has been removed after writing
mocked_fcntl.flock.assert_called_once_with(manager,
mocked_fcntl.LOCK_UN)
示例10: test_replace_filelocking
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_replace_filelocking():
mocked_re = MagicMock()
mocked_fcntl = MagicMock()
mocked_open = MagicMock()
path = 'tests/fixtures/config.conf'
with patch('pyolite.repo.open', mocked_open, create=True):
manager = mocked_open.return_value.__enter__.return_value
# asserts file locking has been put in place before reading
manager.read = lambda: ([
mocked_fcntl.flock.assert_called_once_with(
manager, mocked_fcntl.LOCK_EX
),
mocked_fcntl.reset_mock()
])
with patch.multiple('pyolite.repo', re=mocked_re,
fcntl=mocked_fcntl):
repo = Repo(path)
mocked_fcntl.reset_mock()
repo.replace('pattern', 'string')
# asserts lock has been removed after operating on file
mocked_fcntl.flock.assert_called_once_with(manager,
mocked_fcntl.LOCK_UN)
示例11: test_users_filelocking
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_users_filelocking():
path = 'tests/fixtures/repo_users.conf'
mocked_path = MagicMock()
mocked_path.__str__ = lambda x: path
mocked_path.exists.return_value = True
mocked_re = MagicMock()
mocked_fcntl = MagicMock()
mocked_open = MagicMock()
with patch('pyolite.repo.open', mocked_open, create=True):
manager = mocked_open.return_value.__enter__.return_value
# asserts file locking has been put in place before reading
manager.read = lambda: ([
mocked_fcntl.flock.assert_called_once_with(
manager, mocked_fcntl.LOCK_EX
),
mocked_fcntl.reset_mock()
])
with patch.multiple('pyolite.repo', re=mocked_re,
fcntl=mocked_fcntl):
repo = Repo(mocked_path)
mocked_fcntl.reset_mock()
repo.users
# asserts lock has been removed after reading
mocked_fcntl.flock.assert_called_once_with(manager,
mocked_fcntl.LOCK_UN)
示例12: test_check_jobs
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_check_jobs(jobResetAgent):
"""Test for checkJobs function."""
jobIDs = [1, 2]
dummy_treatJobWithNoReq = MagicMock()
dummy_treatJobWithReq = MagicMock()
# if the readRequestsForJobs func returns error than checkJobs should exit and return an error
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_ERROR()
res = jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
assert not res["OK"]
# test if correct treatment functions are called
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {},
'Failed': {jobIDs[0]: 'Request not found'}})
jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
dummy_treatJobWithNoReq.assert_has_calls([call(jobIDs[0]), call(jobIDs[1])])
dummy_treatJobWithReq.assert_not_called()
dummy_treatJobWithNoReq.reset_mock()
req1 = Request({"RequestID": 1})
req2 = Request({"RequestID": 2})
jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {jobIDs[0]: req1,
jobIDs[1]: req2},
'Failed': {}})
jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
treatJobWithReq=dummy_treatJobWithReq)
dummy_treatJobWithNoReq.assert_not_called()
dummy_treatJobWithReq.assert_has_calls([call(jobIDs[0], req1), call(jobIDs[1], req2)])
示例13: test_iface_discovery
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_iface_discovery(mock_import, mock_provider_check):
""" test iface discovery """
# provider_check is none
mock_provider_check.return_value = 'debian'
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
values = {'netshowlib.debian.iface': mock_debian_iface}
mock_import.side_effect = mod_args_generator(values)
assert_equals(nn.iface('eth1'), 'its a debian bridge')
# if provider_check is not none
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
values['netshowlib.debian.iface'] = mock_debian_iface
assert_equals(nn.iface('eth1', providername='debian'), 'its a debian bridge')
# if cache is set provider_check is none
mock_debian_iface.reset_mock()
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
mock_debian_cache = MagicMock()
values = {'netshowlib.debian.iface': mock_debian_iface,
'netshowlib.debian.cache': mock_debian_cache}
mock_import.side_effect = mod_args_generator(values)
all_cache = nn.feature_cache()
assert_equals(nn.iface('eth1', cache=all_cache),
'its a debian bridge')
# confirm syntax for iface_type accepts cache
mock_debian_iface.iface.assert_called_with('eth1', cache=all_cache)
示例14: test_logs_subcommand
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_logs_subcommand():
get_logs_method = MagicMock()
result_value = ""
get_logs_method.return_value = (True, result_value)
spark_controller.get_logs = get_logs_method
command = "logs -s"
name = "sessions_name"
line = " ".join([command, name])
cell = "cell code"
# Could get results
result = magic.spark(line, cell)
get_logs_method.assert_called_once_with(name)
assert result is None
ipython_display.write.assert_called_once_with(result_value)
# Could not get results
get_logs_method.reset_mock()
get_logs_method.return_value = (False, result_value)
result = magic.spark(line, cell)
get_logs_method.assert_called_once_with(name)
assert result is None
ipython_display.send_error.assert_called_once_with(result_value)
示例15: test_edit_broadcasts
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import reset_mock [as 别名]
def test_edit_broadcasts(self):
sg = self.dc.new_subset_group()
bcast = MagicMock()
sg.subsets[0].broadcast = bcast
bcast.reset_mock()
sg.subsets[0].style.color = 'red'
assert bcast.call_count == 1