本文整理汇总了Python中mock.mock.MagicMock.communicate方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.communicate方法的具体用法?Python MagicMock.communicate怎么用?Python MagicMock.communicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.communicate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_genAgentCrtReq
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import communicate [as 别名]
def test_genAgentCrtReq(self, communicate_mock, popen_mock):
man = CertificateManager(self.config)
p = MagicMock(spec=subprocess.Popen)
p.communicate = communicate_mock
popen_mock.return_value = p
man.genAgentCrtReq()
self.assertTrue(popen_mock.called)
self.assertTrue(communicate_mock.called)
示例2: test_init_warn
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import communicate [as 别名]
def test_init_warn(self,socketListenMock,socketBindMock,popen_mock):
procObj = MagicMock()
procObj.communicate = MagicMock()
procObj.communicate.return_value = {"mine.py": 0, "log": "log"}
popen_mock.return_value = procObj
PingPortListener.logger.reset_mock()
try:
PingPortListener.PingPortListener(self.config)
self.fail("Should throw exception")
except Exception as fe:
# Expected
self.assertEqual(1, procObj.communicate.call_count)
pass
示例3: test_init_success
# 需要导入模块: from mock.mock import MagicMock [as 别名]
# 或者: from mock.mock.MagicMock import communicate [as 别名]
def test_init_success(self,socketMock,popen_mock):
procObj = MagicMock()
procObj.communicate = MagicMock()
procObj.communicate.return_value = {"": 0, "log": "log"}
popen_mock.return_value = procObj
PingPortListener.logger.reset_mock()
popen_mock.reset_mock()
allive_daemon = PingPortListener.PingPortListener(self.config)
self.assertTrue(popen_mock.called)
self.assertFalse(PingPortListener.logger.warn.called)
self.assertTrue(socketMock.call_args_list[0][0][0] == socket.AF_INET)
self.assertTrue(socketMock.call_args_list[0][0][1] == socket.SOCK_STREAM)
self.assertTrue(allive_daemon.socket.bind.call_args_list[0][0][0] == ('0.0.0.0',55000))
self.assertTrue(allive_daemon.socket.listen.call_args_list[0][0][0] == 1)
self.assertTrue(allive_daemon.config.set.call_args_list[0][0][0] == 'agent')
self.assertTrue(allive_daemon.config.set.call_args_list[0][0][1] == 'current_ping_port')