当前位置: 首页>>代码示例>>Python>>正文


Python DeviceTestServer.has_sensor方法代码示例

本文整理汇总了Python中katcp.testutils.DeviceTestServer.has_sensor方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceTestServer.has_sensor方法的具体用法?Python DeviceTestServer.has_sensor怎么用?Python DeviceTestServer.has_sensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在katcp.testutils.DeviceTestServer的用法示例。


在下文中一共展示了DeviceTestServer.has_sensor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_DeviceServer

# 需要导入模块: from katcp.testutils import DeviceTestServer [as 别名]
# 或者: from katcp.testutils.DeviceTestServer import has_sensor [as 别名]
class test_DeviceServer(unittest.TestCase, TestUtilMixin):
    def setUp(self):
        self.server = DeviceTestServer('', 0)

    def test_on_client_connect(self):
        fake_sock = mock.Mock()
        mock_conn = mock.Mock(
            spec=katcp.server.ClientConnection(self.server._server, fake_sock))
        self.server.BUILD_INFO = ('buildy', 1, 2, 'g')
        self.server.VERSION_INFO = ('deviceapi', 5, 6)
        # Hack around ioloop thread asserts
        self.server._server.ioloop_thread_id = thread.get_ident()
        # Test call
        self.server.on_client_connect(mock_conn)
        # we are expecting 3 inform messages
        no_msgs = 3
        self.assertEqual(mock_conn.inform.call_count, no_msgs)
        # Get all the messages sent to _send_message
        msgs = [str(call[0][0]) for call in mock_conn.inform.call_args_list]
        katcp_version = __version__
        self._assert_msgs_equal(msgs, (
            r'#version-connect katcp-protocol 5.0-IM',
            # Will have to be updated for every library version bump
            r'#version-connect katcp-library katcp-python-%s' % katcp_version,
            r'#version-connect katcp-device deviceapi-5.6 buildy-1.2g'))

    def test_request_sensor_sampling_clear(self):
        self.server.clear_strategies = mock.Mock()
        start_thread_with_cleanup(self, self.server, start_timeout=1)
        client_connection = ClientConnectionTest()
        self.server.ioloop.make_current()
        tf = self.server.handle_message(
            client_connection, katcp.Message.request('sensor-sampling-clear'))
        # tf may be a tornado (not thread-safe) future, so we wrap it in a thread-safe
        # future object
        f = Future()
        self.server.ioloop.add_callback(gen.chain_future, tf, f)
        f.result(timeout=1)
        # Ensure that the tornado future has finished running its callbacks
        self.server.sync_with_ioloop()
        self._assert_msgs_equal(client_connection.messages, [
            '!sensor-sampling-clear ok'])
        self.server.clear_strategies.assert_called_once_with(client_connection)

    def test_has_sensor(self):
        self.assertFalse(self.server.has_sensor('blaah'))
        self.server.add_sensor(katcp.Sensor.boolean('blaah', 'blaah sens'))
        self.assertTrue(self.server.has_sensor('blaah'))
开发者ID:ska-sa,项目名称:katcp-python,代码行数:50,代码来源:test_server.py

示例2: test_DeviceServer

# 需要导入模块: from katcp.testutils import DeviceTestServer [as 别名]
# 或者: from katcp.testutils.DeviceTestServer import has_sensor [as 别名]
class test_DeviceServer(unittest.TestCase, TestUtilMixin):
    def setUp(self):
        self.server = DeviceTestServer('', 0)

    def test_on_client_connect(self):
        conn = katcp.server.ClientConnectionTCP(self.server, 'fake-sock')
        m_sm = self.server._send_message = mock.Mock()
        self.server.BUILD_INFO = ('buildy', 1, 2, 'g')
        self.server.VERSION_INFO = ('deviceapi', 5, 6)
        self.server.on_client_connect(conn)
        # we are expecting 3 inform messages
        no_msgs = 3
        self.assertEqual(m_sm.call_count, no_msgs)
        # Check that calls were syntactically valid
        self.assertEqual(m_sm.call_args_list,
                         [mock.call('fake-sock', mock.ANY)]*no_msgs)
        # Get all the messages sent to _send_message
        msgs = [str(call[0][1]) for call in m_sm.call_args_list]
        self._assert_msgs_equal(msgs, (
            r'#version-connect katcp-protocol 5.0-IM',
            # Will have to be updated for every library version bump
            r'#version-connect katcp-library katcp-python-0.5.4',
            r'#version-connect katcp-device deviceapi-5.6 buildy-1.2g') )

    def test_request_sensor_sampling_clear(self):
        self.server.clear_strategies = mock.Mock()
        client_connection = ClientConnectionTest()
        self.server.handle_message(
            client_connection, katcp.Message.request('sensor-sampling-clear'))
        self._assert_msgs_equal(client_connection.messages, [
            '!sensor-sampling-clear ok'])
        self.server.clear_strategies.assert_called_once_with(client_connection)

    def test_has_sensor(self):
        self.assertFalse(self.server.has_sensor('blaah'))
        self.server.add_sensor(katcp.Sensor.boolean('blaah', 'blaah sens'))
        self.assertTrue(self.server.has_sensor('blaah'))
开发者ID:braamotto,项目名称:katcp-python,代码行数:39,代码来源:test_server.py


注:本文中的katcp.testutils.DeviceTestServer.has_sensor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。