本文整理汇总了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,