本文整理汇总了Python中katcp.testutils.DeviceTestServer.get_sensor方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceTestServer.get_sensor方法的具体用法?Python DeviceTestServer.get_sensor怎么用?Python DeviceTestServer.get_sensor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类katcp.testutils.DeviceTestServer
的用法示例。
在下文中一共展示了DeviceTestServer.get_sensor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ThreadSafeKATCPClientResourceWrapper
# 需要导入模块: from katcp.testutils import DeviceTestServer [as 别名]
# 或者: from katcp.testutils.DeviceTestServer import get_sensor [as 别名]
class test_ThreadSafeKATCPClientResourceWrapper(unittest.TestCase):
def setUp(self):
self.server = DeviceTestServer('', 0)
start_thread_with_cleanup(self, self.server)
self.ioloop_manager = ioloop_manager.IOLoopManager(managed_default=True)
self.io_loop = self.ioloop_manager.get_ioloop()
self.host, self.port = self.server.bind_address
self.default_resource_spec = dict(
name='thething',
address=self.server.bind_address,
controlled=True)
self.client_resource = resource_client.KATCPClientResource(
self.default_resource_spec)
self.client_resource.set_ioloop(self.io_loop)
self.io_loop.add_callback(self.client_resource.start)
self.ioloop_thread_wrapper = resource_client.IOLoopThreadWrapper(self.io_loop)
start_thread_with_cleanup(self, self.ioloop_manager, start_timeout=1)
self.ioloop_thread_wrapper.default_timeout = 1
self.DUT = resource_client.ThreadSafeKATCPClientResourceWrapper(
self.client_resource, self.ioloop_thread_wrapper)
self.DUT.until_synced()
def test_wrapped_timeout(self):
self.assertEqual(self.client_resource.state, 'synced')
# Test timeout
self.ioloop_thread_wrapper.default_timeout = 0.001
t0 = time.time()
with self.assertRaises(TimeoutError):
self.DUT.until_state('disconnected')
self.assertLess(time.time() - t0, 0.2)
# Now make sure we can actualy still wait on the state
self.ioloop_thread_wrapper.default_timeout = 1
self.server.stop()
self.server.join()
self.DUT.until_state('disconnected')
self.assertEqual(self.client_resource.state, 'disconnected')
self.server.start()
self.DUT.until_state('synced')
self.assertEqual(self.client_resource.state, 'synced')
def test_request(self):
reply = self.DUT.req.sensor_value('an.int')
last_server_msg = self.server.messages[-1]
self.assertTrue(reply.succeeded)
self.assertEqual(str(last_server_msg),
'?sensor-value[{}] an.int'.format(reply.reply.mid))
def test_sensor(self):
server_sensor = self.server.get_sensor('an.int')
reading = self.DUT.sensor.an_int.get_reading()
self.assertEqual(reading.value, server_sensor.read().value)
server_sensor.set_value(server_sensor.read().value + 5)
reading = self.DUT.sensor.an_int.get_reading()
self.assertEqual(reading.value, server_sensor.read().value)
示例2: TestInspectingClientAsync
# 需要导入模块: from katcp.testutils import DeviceTestServer [as 别名]
# 或者: from katcp.testutils.DeviceTestServer import get_sensor [as 别名]
class TestInspectingClientAsync(tornado.testing.AsyncTestCase):
def setUp(self):
super(TestInspectingClientAsync, self).setUp()
self.server = DeviceTestServer('', 0)
start_thread_with_cleanup(self, self.server, start_timeout=1)
self.host, self.port = self.server.bind_address
self.client = InspectingClientAsync(self.host, self.port,
ioloop=self.io_loop)
self.io_loop.add_callback(self.client.connect)
@tornado.testing.gen_test
def test_simple_request(self):
"""Perform a basic request."""
yield self.client.until_synced()
reply, informs = yield self.client.simple_request('help', 'watchdog')
self.assertIn('ok', str(reply))
self.assertEquals(len(informs), 1)
@tornado.testing.gen_test
def test_sensor(self):
"""Access the sensor with the Async client."""
yield self.client.until_synced()
sensor_name = 'an.int'
sensor = yield self.client.future_get_sensor(sensor_name)
self.assertEquals(sensor.name, sensor_name)
self.assertEquals(sensor.stype, 'integer')
# Unknown sensor requests return a None.
sensor_name = 'thing.unknown_sensor'
sensor = yield self.client.future_get_sensor(sensor_name)
self.assertIsNone(sensor)
@tornado.testing.gen_test
def test_request_access(self):
"""Test access to requests."""
yield self.client.until_synced()
request_name = 'watchdog'
self.assertIn(request_name, self.client.requests)
request = yield self.client.future_get_request(request_name)
self.assertEqual(request.name, request_name)
self.assertTrue(request.description,
'Expected an description: got nothing.')
# Unknown request return a None.
request_name = 'watchcat'
self.assertNotIn(request_name, self.client.requests)
request = yield self.client.future_get_request(request_name)
self.assertIsNone(request)
@tornado.testing.gen_test
def test_sensor_add_remove(self):
"""Test a sensor being added and then remove it."""
yield self.client.until_synced()
sensor = DeviceTestSensor(Sensor.INTEGER, "another.int",
"An Integer.",
"count", [-5, 5], timestamp=time.time(),
status=Sensor.NOMINAL, value=3)
# Check that the sensor does not exist currently
self.assertNotIn(sensor.name, self.client.sensors)
# Add a sensor.
self.server.add_sensor(sensor)
self.server.mass_inform(Message.inform('interface-changed'))
# Do a blocking request to ensure #interface-changed has been received
yield self.client.simple_request('watchdog')
yield self.client.until_synced()
self.assertIn('another.int', self.client.sensors)
# Remove a sensor.
self.server.remove_sensor(sensor)
self.server.mass_inform(Message.inform('interface-changed'))
# Do a blocking request to ensure #interface-changed has been received
yield self.client.simple_request('watchdog')
yield self.client.until_synced()
self.assertNotIn('another.int', self.client.sensors)
@tornado.testing.gen_test
def test_request_add_remove(self):
"""Test a request being added and then remove it."""
yield self.client.until_synced()
def request_sparkling_new(self, req, msg):
"""A new command."""
return Message.reply(msg.name, "ok", "bling1", "bling2")
# Check that the request did not exist before
self.assertNotIn('sparkling-new', self.client.requests)
# Add a request.
self.server.request_sparkling_new = request_sparkling_new
self.server._request_handlers['sparkling-new'] = request_sparkling_new
self.server.mass_inform(Message.inform('interface-changed'))
# Do a blocking request to ensure #interface-changed has been received
#.........这里部分代码省略.........