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


Python CommandResponseInstrumentProtocol._verify_not_readonly方法代码示例

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


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

示例1: TestUnitInstrumentProtocol

# 需要导入模块: from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol [as 别名]
# 或者: from mi.core.instrument.instrument_protocol.CommandResponseInstrumentProtocol import _verify_not_readonly [as 别名]

#.........这里部分代码省略.........
                    }
                }
            }
        }

        self.protocol.set_init_params(startup_config)

        # Verify we are initialized properly
        self.assertIsNone(self.protocol._scheduler)
        self.assertEqual(self.protocol._scheduler_config, {})
        self.assertEqual(self.protocol._scheduler_callback, {})

        # Verify the the scheduler is created
        self.protocol.initialize_scheduler()
        self.assertIsInstance(self.protocol._scheduler, DriverScheduler)
        self.assertEqual(self.protocol._scheduler_config, {})
        self.assertEqual(self.protocol._scheduler_callback, {})

        # Now lets see some magic happen.  Lets add our schedulers.  Generally
        # This would be done as part of the protocol init, but it can happen
        # anytime.  If the scheduler has already been initialized the
        # job will be started right away
        foo_event='foo'
        bar_event='bar'
        self.protocol._add_scheduler_event(foo_scheduler, foo_event)
        self.protocol._add_scheduler_event(bar_scheduler, bar_event)

        self.assertEqual(0, self._trigger_count)
        #self.assert_scheduled_event_triggered(2)

        ##### Integration tests for test_scheduler in the SBE37 integration suite

    def test_generate_config_metadata_json(self):
        """ Tests generate of the metadata structure """
        self.protocol._param_dict.add("foo", r'foo=(.*)',
                             lambda match : int(match.group(1)),
                             lambda x : str(x),
                             direct_access=True,
                             default_value=10)
        self.protocol._param_dict.add("bar", r'bar=(.*)',
                             lambda match : int(match.group(1)),
                             lambda x : str(x),
                             direct_access=False,
                             default_value=15)

        self.protocol._cmd_dict.add("cmd1",
                                    timeout=60,
                                    arguments=[CommandArgument("coeff"),
                                               CommandArgument("delay")
                                              ]
                                   )
        # different way of creating things, possibly more clear in some cases
        # and allows for testing arg and command later
        cmd2_arg1 = CommandArgument("trigger")
        cmd2 = Command("cmd2", arguments=[cmd2_arg1])
        
        self.protocol._cmd_dict.add_command(cmd2)

        self.protocol._driver_dict.add(DriverDictKey.VENDOR_SW_COMPATIBLE, True)

        # Now do the real testing       
        result = self.protocol.get_config_metadata_dict()
        
        self.assert_(isinstance(result[ConfigMetadataKey.DRIVER], dict))
        self.assert_(isinstance(result[ConfigMetadataKey.COMMANDS], dict))
        self.assert_(isinstance(result[ConfigMetadataKey.PARAMETERS], dict))
        
        self.assertEquals(result[ConfigMetadataKey.DRIVER],
                          {DriverDictKey.VENDOR_SW_COMPATIBLE:True})

        # Check a few in the cmd list...the leaves in the structure are
        # tested in the cmd dict test cases
        self.assert_("cmd1" in result[ConfigMetadataKey.COMMANDS].keys())
        self.assert_("cmd2" in result[ConfigMetadataKey.COMMANDS].keys())
                
        # Check a few in the param list...the leaves in the structure are
        # tested in the param dict test cases
        self.assert_("foo" in result[ConfigMetadataKey.PARAMETERS].keys())
        self.assert_("bar" in result[ConfigMetadataKey.PARAMETERS].keys())

    def test_verify_muttable(self):
        """
        Verify the verify_not_read_only works as expected.
        """
        self.protocol._param_dict.add('ro', r'', None, None, visibility=ParameterDictVisibility.READ_ONLY)
        self.protocol._param_dict.add('immutable', r'', None, None, visibility=ParameterDictVisibility.IMMUTABLE)
        self.protocol._param_dict.add('rw', r'', None, None, visibility=ParameterDictVisibility.READ_WRITE)

        # Happy Path
        self.protocol._verify_not_readonly({'rw': 1})
        self.protocol._verify_not_readonly({'rw': 1, 'immutable': 2}, startup=True)

        with self.assertRaises(InstrumentParameterException):
            self.protocol._verify_not_readonly({'rw': 1, 'immutable': 2})

        with self.assertRaises(InstrumentParameterException):
            self.protocol._verify_not_readonly({'rw': 1, 'ro': 2})

        with self.assertRaises(InstrumentParameterException):
            self.protocol._verify_not_readonly({'rw': 1, 'ro': 2}, startup=True)
开发者ID:aplmmilcic,项目名称:mi-instrument,代码行数:104,代码来源:test_instrument_protocol.py


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