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


Python CommandResponseInstrumentProtocol._get_param_list方法代码示例

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


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

示例1: TestUnitInstrumentProtocol

# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _get_param_list [as 别名]
class TestUnitInstrumentProtocol(MiUnitTestCase):
    """
    Test cases for instrument protocol class. Functions in this class provide
    instrument protocol unit tests and provide a tutorial on use of
    the protocol interface.
    """ 
    def setUp(self):
        """
        """
        self.callback_result = None
        self._trigger_count = 0
        self._events = []

        self.protocol = InstrumentProtocol(self.event_callback)

    def tearDown(self):
        if self.protocol._scheduler:
            self.protocol._scheduler._scheduler.shutdown()
                
    def event_callback(self, event, value=None):
        log.debug("Test event callback: %s" % event)
        self._events.append(event)
        self._trigger_count += 1

    def _scheduler_callback(self):
        """
        Callback to test the scheduler
        """
        self._trigger_count += 1

    def assert_scheduled_event_triggered(self, event_count=1):
        count = 0
        for i in range(0, 40):
            count = self._trigger_count
            log.debug("check for triggered event, count %d" % self._trigger_count)
            if(count >= event_count): break
            time.sleep(0.3)

        self.assertGreater(count, 0)

    def test_get_prompts(self):
        """
        ensure prompts are returned sorted by length
        """
        prompts = ['aa', 'bbb', 'c', 'dddd']
        expected = ['dddd', 'bbb', 'aa', 'c']
        class Prompts(BaseEnum):
            A = 'aa'
            B = 'bbb'
            C = 'c'
            D = 'dddd'

        self.protocol = CommandResponseInstrumentProtocol(prompts, '\r\n', self.event_callback)
        self.assertEqual(self.protocol._get_prompts(), expected)

        self.protocol = CommandResponseInstrumentProtocol(Prompts, '\r\n', self.event_callback)
        self.assertEqual(self.protocol._get_prompts(), expected)

    def test_extraction(self):
        sample_line = "SATPAR0229,10.01,2206748544,234\r\n"
        ntptime = ntplib.system_to_ntp_time(time.time())
        result = self.protocol._extract_sample(SatlanticPARDataParticle,
                                               SAMPLE_REGEX,
                                               sample_line,
                                               ntptime,
                                               publish=False)

        log.debug("R: %s" % result)
        self.assertEqual(result['stream_name'], SatlanticPARDataParticle(None, None).data_particle_type())

        # Test the format of the result in the individual driver tests. Here,
        # just tests that the result is there.

    def test_get_param_list(self):
        """
        verify get_param_list returns correct parameter lists.
        """
        params = ['foo', 'bar', 'baz']

        for key in params:
            self.protocol._param_dict.add(key, r'', None, None)

        # All can be passed in as a string
        self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(DriverParameter.ALL)))

        # All can be passed in as a single element list
        self.assertEqual(sorted(params), sorted(self.protocol._get_param_list([DriverParameter.ALL])))

        # All can be in a list anywhere, not just the first element
        self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(['foo', DriverParameter.ALL])))

        # Bad parameters raise exceptions event when ALL is specified
        with self.assertRaises(InstrumentParameterException):
            self.assertEqual(sorted(params), sorted(self.protocol._get_param_list(['noparam', DriverParameter.ALL])))

        # An exception is raised when the param is not a list or string
        with self.assertRaises(InstrumentParameterException):
            self.protocol._get_param_list({'other': 'struct'})

        # when a subset is given, the same set is returned.
#.........这里部分代码省略.........
开发者ID:aplmmilcic,项目名称:mi-instrument,代码行数:103,代码来源:test_instrument_protocol.py


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