本文整理汇总了Python中mock.mock.MagicMock.get方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.get方法的具体用法?Python MagicMock.get怎么用?Python MagicMock.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reset
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import get [as 别名]
def test_reset(self, os_remove_mock, os_walk_mock, sys_exit_mock, config_parser_mock, open_mock, os_path_join_mock, os_rmdir_mock):
# Agent config update
config_mock = MagicMock()
os_walk_mock.return_value = [('/', ('',), ('file1.txt', 'file2.txt'))]
config_parser_mock.return_value= config_mock
config_mock.get('server', 'hostname').return_value = "old_host"
main.reset_agent(["test", "reset", "new_hostname"])
self.assertEqual(config_mock.get.call_count, 3)
self.assertEqual(config_mock.set.call_count, 1)
self.assertEqual(os_remove_mock.call_count, 2)
self.assertTrue(sys_exit_mock.called)
示例2: test_reset_invalid_path
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import get [as 别名]
def test_reset_invalid_path(self, os_remove_mock, os_walk_mock, sys_exit_mock,
config_parser_mock, open_mock, os_path_join_mock, os_rmdir_mock):
# Agent config file cannot be accessed
config_mock = MagicMock()
os_walk_mock.return_value = [('/', ('',), ('file1.txt', 'file2.txt'))]
config_parser_mock.return_value= config_mock
config_mock.get('server', 'hostname').return_value = "old_host"
open_mock.side_effect = Exception("Invalid Path!")
try:
main.reset_agent(["test", "reset", "new_hostname"])
self.fail("Should have thrown exception!")
except:
self.assertTrue(True)
self.assertTrue(sys_exit_mock.called)