本文整理汇总了Python中salttesting.mock.MagicMock.reset_mock方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.reset_mock方法的具体用法?Python MagicMock.reset_mock怎么用?Python MagicMock.reset_mock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salttesting.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.reset_mock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_disable
# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import reset_mock [as 别名]
def test_disable(self):
"""
Test for Disable the named service to start at boot
"""
rc_update_mock = MagicMock(return_value=0)
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name'))
rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False)
rc_update_mock.reset_mock()
# disable service
service_name = 'name'
runlevels = ['l1']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name', runlevels='l1'))
rc_update_mock.assert_called_once_with('rc-update delete name l1',
python_shell=False)
rc_update_mock.reset_mock()
# same as above with list
runlevels = ['l1']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
rc_update_mock.assert_called_once_with('rc-update delete name l1',
python_shell=False)
rc_update_mock.reset_mock()
# remove from 'l1', and leave at 'l2'
runlevels = ['l1', 'l2']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
rc_update_mock.assert_called_once_with('rc-update delete name l1',
python_shell=False)
rc_update_mock.reset_mock()
# remove from non-enabled level
runlevels = ['l2']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
rc_update_mock.assert_not_called()
rc_update_mock.reset_mock()
# remove from 'l1' and 'l3', leave at 'l2'
runlevels = ['l1', 'l2', 'l3']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.disable('name', runlevels=['l1', 'l3']))
rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
python_shell=False)
rc_update_mock.reset_mock()
# rc-update failed
rc_update_mock = MagicMock(return_value=1)
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.disable('name'))
rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False)
rc_update_mock.reset_mock()
# move service delete failed
runlevels = ['l1']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.disable('name', runlevels='l1'))
rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False)
rc_update_mock.reset_mock()
# move service delete succeeds. add fails
runlevels = ['l1', 'l2', 'l3']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.disable('name', runlevels=['l1', 'l3']))
rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
python_shell=False)
rc_update_mock.reset_mock()
示例2: test_enable
# 需要导入模块: from salttesting.mock import MagicMock [as 别名]
# 或者: from salttesting.mock.MagicMock import reset_mock [as 别名]
def test_enable(self):
"""
Test for Enable the named service to start at boot
"""
rc_update_mock = MagicMock(return_value=0)
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name'))
rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False)
rc_update_mock.reset_mock()
# move service from 'l1' to 'l2' runlevel
service_name = 'name'
runlevels = ['l1']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels='l2'))
rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False),
call('rc-update add name l2', python_shell=False)])
rc_update_mock.reset_mock()
# requested levels are the same as the current ones
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels='l1'))
rc_update_mock.assert_not_called()
rc_update_mock.reset_mock()
# same as above with the list instead of the string
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels=['l1']))
rc_update_mock.assert_not_called()
rc_update_mock.reset_mock()
# add service to 'l2' runlevel
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels=['l2', 'l1']))
rc_update_mock.assert_called_once_with('rc-update add name l2', python_shell=False)
rc_update_mock.reset_mock()
# remove service from 'l1' runlevel
runlevels = ['l1', 'l2']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels=['l2']))
rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False)
rc_update_mock.reset_mock()
# move service from 'l2' add to 'l3', leaving at l1
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels=['l1', 'l3']))
rc_update_mock.assert_has_calls([call('rc-update delete name l2', python_shell=False),
call('rc-update add name l3', python_shell=False)])
rc_update_mock.reset_mock()
# remove from l1, l3, and add to l2, l4, and leave at l5
runlevels = ['l1', 'l3', 'l5']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertTrue(gentoo_service.enable('name', runlevels=['l2', 'l4', 'l5']))
rc_update_mock.assert_has_calls([call('rc-update delete name l1 l3', python_shell=False),
call('rc-update add name l2 l4', python_shell=False)])
rc_update_mock.reset_mock()
# rc-update failed
rc_update_mock = MagicMock(return_value=1)
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.enable('name'))
rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False)
rc_update_mock.reset_mock()
# move service delete failed
runlevels = ['l1']
level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.enable('name', runlevels='l2'))
rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False)
rc_update_mock.reset_mock()
# move service delete succeeds. add fails
rc_update_mock = MagicMock()
rc_update_mock.side_effect = [0, 1]
with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
self.assertFalse(gentoo_service.enable('name', runlevels='l2'))
rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False),
call('rc-update add name l2', python_shell=False)])
rc_update_mock.reset_mock()