本文整理汇总了Python中twisted.internet.protocol.ClientFactory.comaster方法的典型用法代码示例。如果您正苦于以下问题:Python ClientFactory.comaster方法的具体用法?Python ClientFactory.comaster怎么用?Python ClientFactory.comaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.ClientFactory
的用法示例。
在下文中一共展示了ClientFactory.comaster方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_peh_upon_connection
# 需要导入模块: from twisted.internet.protocol import ClientFactory [as 别名]
# 或者: from twisted.internet.protocol.ClientFactory import comaster [as 别名]
def test_send_peh_upon_connection(self):
'''To test client protocol we isloate it from the ClientFactory'''
with patch.object(datetime, 'datetime', Mock(wraps=datetime.datetime)) as patched:
fixed_date = datetime.datetime(2014, 1, 1, 12, 0, 0)
patched.now.return_value = fixed_date
factory = ClientFactory()
factory.comaster = self.comaster
factory.protocol = MaraClientProtocol
proto = factory.buildProtocol(('127.0.0.1', 0))
proto.construct = MaraFrame
# Disable unnesesary behaviour
def stop():
proto.stop()
reactor.stop()
proto.sendPoll = MagicMock(side_effect=stop)
transport = proto_helpers.StringTransport()
proto.makeConnection(transport)
bytes_sent_to_device = transport.value()
result = MaraFrame.parse(bytes_sent_to_device)
self.assertEqual(result.dest, 0xFF)
self.assertEqual(result.source, 2)
# We don't need to check BCC since it's already coded into MaraFrame
self.assertEqual(result.peh, fixed_date)
reactor.run()
# Shuld have stopped
self.assertEqual(self.comaster.update_peh_timestamp.call_count, 1)
self.assertEqual(self.comaster.update_peh_timestamp.call_args[0][0],
fixed_date)