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


Python SingleConnectionInstrumentDriver.get_config_metadata方法代码示例

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


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

示例1: TestUnitInstrumentDriver

# 需要导入模块: from mi.core.instrument.instrument_driver import SingleConnectionInstrumentDriver [as 别名]
# 或者: from mi.core.instrument.instrument_driver.SingleConnectionInstrumentDriver import get_config_metadata [as 别名]

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

        self.assertFalse(exception)

    def test_direct_access_params(self):
        """
        Tests to see how direct access parameters are setup and that they are
        working properly.
        """        
        self.assertTrue(self.driver._protocol._param_dict.get("foo"), 10)
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 15)
        # use real driver sets here, the direct poke of the param dict is just
        # a test-with-base-class thing
        self.driver._protocol._param_dict.update("bar=20")
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 20)
        
        # pretend to go into direct access mode,
        running_config = self.driver._protocol.get_cached_config()
        #   make some changes to both, (foo to 100, bar to 200)
        self.driver._protocol._param_dict.update("foo=100")
        self.driver._protocol._param_dict.update("bar=200")        
        # its like we came out of DA mode
        self.driver.restore_direct_access_params(running_config)

        # confirm that the default values were set back appropriately.
        self.assertTrue(self.driver._protocol._param_dict.get("foo"), 10)
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 200)
        
    def test_get_cached_config(self):
        """
        Verifies that the driver kicks out a cached config. Not connected, but
        thats what it is headed...
        """
        running_config = self.driver.get_cached_config()
        self.assertEquals(running_config["foo"], 10)
        self.assertEquals(running_config["bar"], 15)        
        
    def test_apply_startup_params(self):
        """
        Test to see that calling a driver's apply_startup_params successfully
        gets down into the base protocol class's apply_startup_params() stub
        that throws an exception
        """
        self.assertRaises(NotImplementedException,
                          self.driver.apply_startup_params)
        
    def test_config_metadata(self):
        """
        Test the metadata structure fetch
        """
        json_result = self.driver.get_config_metadata()
        self.assert_(isinstance(json_result, str))
        self.assert_(len(json_result) > 100)
        result = json.loads(json_result)
        
        self.assert_(isinstance(result[ConfigMetadataKey.DRIVER], dict))
        self.assert_(isinstance(result[ConfigMetadataKey.COMMANDS], dict))
        self.assert_(isinstance(result[ConfigMetadataKey.PARAMETERS], dict))
        
        self.assertEquals(len(result[ConfigMetadataKey.DRIVER]), 1)
        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.assertEquals(len(result[ConfigMetadataKey.COMMANDS]), 2)
        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.assertEquals(len(result[ConfigMetadataKey.PARAMETERS]), 4)
        self.assert_("foo" in result[ConfigMetadataKey.PARAMETERS].keys())
        self.assert_("bar" in result[ConfigMetadataKey.PARAMETERS].keys())  
        self.assert_("baz" in result[ConfigMetadataKey.PARAMETERS].keys())  
        self.assert_("bat" in result[ConfigMetadataKey.PARAMETERS].keys())  
        
    def test_startup_params(self):
        """
        Tests to see that startup parameters are properly set when the
        startup logic goes through.
        """
        self.assertTrue(self.driver._protocol._param_dict.get("foo"), 10)
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 15)
        # make sure some value isnt the default value
        self.driver._protocol._param_dict.update("bar=20")
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 20)
        self.driver._protocol._param_dict.update("baz=30")
        self.assertTrue(self.driver._protocol._param_dict.get("baz"), 30)
        
        # pretend to manually adjust a few things:
        self.driver._protocol._param_dict.update("foo=1000")
        self.assertTrue(self.driver._protocol._param_dict.get("foo"), 1000)
        self.driver._protocol._param_dict.update("bar=1500")
        self.assertTrue(self.driver._protocol._param_dict.get("bar"), 1500)
        self.driver._protocol._param_dict.update("baz=2000")
        self.assertTrue(self.driver._protocol._param_dict.get("baz"), 2000)
        
        # pretend to go through the motions of a startup sequence
        self.driver.set_init_params({'foo':100, "bar": 150, "baz": 200})
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:104,代码来源:test_instrument_driver.py


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