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


Python ProtocolParameterDict.format方法代码示例

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


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

示例1: TestUnitProtocolParameterDict

# 需要导入模块: from mi.core.instrument.protocol_param_dict import ProtocolParameterDict [as 别名]
# 或者: from mi.core.instrument.protocol_param_dict.ProtocolParameterDict import format [as 别名]

#.........这里部分代码省略.........
    def test_schema_generation(self):
        self.maxDiff = None
        result = self.param_dict.generate_dict()
        json_result = json.dumps(result, indent=4, sort_keys=True)
        log.debug("Expected: %s", self.target_schema)
        log.debug("Result: %s", json_result)
        self.assertEqual(result, self.target_schema)

    def test_empty_schema(self):
        self.param_dict = ProtocolParameterDict()
        result = self.param_dict.generate_dict()
        self.assertEqual(result, {})

    def test_bad_descriptions(self):
        self.param_dict._param_dict["foo"].description = None
        self.param_dict._param_dict["foo"].value = None
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_init_value, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_default_value, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.set_default, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_init_value, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_menu_path_read, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_submenu_read, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_menu_path_write, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_submenu_write, "foo")
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.format, "foo", 1)
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.get_direct_access_list)
        self.assertRaises(InstrumentParameterException,
                          self.param_dict.is_startup_param, "foo")

    def test_set(self):
        """
        Test a simple set of the parameter. Make sure the right values get
        called and the correct exceptions are raised.
        """
        new_param = FunctionParameter("foo",
                                      self.pick_byte2,
                                      lambda x: str(x),
                                      direct_access=True,
                                      startup_param=True,
                                      value=1000,
                                      visibility=ParameterDictVisibility.READ_WRITE)
        self.assertEquals(new_param.get_value(), 1000)
        self.assertEquals(self.param_dict.get("foo"), None)
        # overwrites existing param
        self.param_dict.add_parameter(new_param)
        self.assertEquals(self.param_dict.get("foo"), 1000)
        self.param_dict.set_value("foo", 2000)
        self.assertEquals(self.param_dict.get("foo"), 2000)

    def test_invalid_type(self):
        self.assertRaises(InstrumentParameterException,
                          FunctionParameter,
                          "fn_bar",
                          lambda x: bool(x & 2),  # bit map example
                          lambda x: str(x),
                          direct_access=True,
开发者ID:kehunt06,项目名称:mi-instrument,代码行数:70,代码来源:test_protocol_param_dict.py


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