本文整理汇总了Python中katcp.testutils.DeviceTestServer.messages方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceTestServer.messages方法的具体用法?Python DeviceTestServer.messages怎么用?Python DeviceTestServer.messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类katcp.testutils.DeviceTestServer
的用法示例。
在下文中一共展示了DeviceTestServer.messages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDeviceClientIntegrated
# 需要导入模块: from katcp.testutils import DeviceTestServer [as 别名]
# 或者: from katcp.testutils.DeviceTestServer import messages [as 别名]
class TestDeviceClientIntegrated(unittest.TestCase, TestUtilMixin):
def setUp(self):
self.server = DeviceTestServer('', 0)
self.server.start(timeout=0.1)
host, port = self.server._sock.getsockname()
self.client = katcp.DeviceClient(host, port)
self.client.start(timeout=0.1)
def tearDown(self):
if self.client.running():
self.client.stop()
self.client.join()
if self.server.running():
self.server.stop()
self.server.join()
def test_request(self):
"""Test request method."""
self.assertTrue(self.client.wait_protocol(1))
self.client.send_request(katcp.Message.request("watchdog"))
self.client.send_request(katcp.Message.request("watchdog", mid=55))
self.client._server_supports_ids = False
with self.assertRaises(katcp.core.KatcpVersionError):
self.client.send_request(katcp.Message.request("watchdog", mid=56))
time.sleep(0.1)
msgs = self.server.messages()
self._assert_msgs_equal(msgs, [
r"?watchdog",
r"?watchdog[55]",
])
def test_send_message(self):
"""Test send_message method."""
self.client.send_message(katcp.Message.inform("random-inform"))
time.sleep(0.1)
msgs = self.server.messages()
self._assert_msgs_equal(msgs, [
r"#random-inform",
])
def test_stop_and_restart(self):
"""Test stopping and then restarting a client."""
self.client.stop(timeout=0.1)
# timeout needs to be longer than select sleep.
self.client.join(timeout=1.5)
self.assertEqual(self.client._thread, None)
self.assertFalse(self.client._running.isSet())
self.client.start(timeout=0.1)
def test_is_connected(self):
"""Test is_connected method."""
self.assertTrue(self.client.is_connected())
self.server.stop(timeout=0.1)
# timeout needs to be longer than select sleep.
self.server.join(timeout=1.5)
self.assertFalse(self.client.is_connected())
def test_wait_connected(self):
"""Test wait_connected method."""
start = time.time()
self.assertTrue(self.client.wait_connected(1.0))
self.assertTrue(time.time() - start < 1.0)
self.server.stop(timeout=0.1)
# timeout needs to be longer than select sleep.
self.server.join(timeout=1.5)
start = time.time()
self.assertFalse(self.client.wait_connected(0.2))
self.assertTrue(0.15 < time.time() - start < 0.25)
def test_bad_socket(self):
"""Test what happens when select is called on a dead socket."""
# wait for client to connect
time.sleep(0.1)
# close socket while the client isn't looking
# then wait for the client to notice
sock = self.client._sock
sockname = sock.getpeername()
sock.close()
time.sleep(1.25)
# check that client reconnected
self.assertTrue(sock is not self.client._sock,
"Expected %r to not be %r" % (sock, self.client._sock))
self.assertEqual(sockname, self.client._sock.getpeername())
def test_daemon_value(self):
"""Test passing in a daemon value to client start method."""
self.client.stop(timeout=0.1)
# timeout needs to be longer than select sleep.
self.client.join(timeout=1.5)
self.client.start(timeout=0.1, daemon=True)
self.assertTrue(self.client._thread.isDaemon())
#.........这里部分代码省略.........