本文整理匯總了Python中traitlets.Float方法的典型用法代碼示例。如果您正苦於以下問題:Python traitlets.Float方法的具體用法?Python traitlets.Float怎麽用?Python traitlets.Float使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類traitlets
的用法示例。
在下文中一共展示了traitlets.Float方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def __init__(self, driver, led_type: LEDType, *args, **kwargs):
super(LED, self).__init__(*args, **kwargs)
self._driver = driver
self._led_type = led_type
self._logger = driver.logger
self.led_type = led_type
self._restoring = True
self._refreshing = False
self._dirty = True
# dynamic traits, since they are normally class-level
brightness = Float(min=0.0, max=100.0, default_value=80.0,
allow_none=False).tag(config=True)
color = ColorTrait(default_value=led_type.default_color,
allow_none=False).tag(config=led_type.rgb)
mode = UseEnumCaseless(enum_class=LEDMode, default_value=LEDMode.STATIC,
allow_none=False).tag(config=led_type.has_modes)
self.add_traits(color=color, mode=mode, brightness=brightness)
self._restoring = False
示例2: test_tool_simple
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_tool_simple():
"""test the very basic functionality of a Tool"""
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
tool.userparam = 1.0
tool.log_level = "DEBUG"
tool.log.info("test")
with pytest.raises(SystemExit) as exc:
tool.run([])
assert exc.value.code == 0
# test parameters changes:
tool.userparam = 4.0
with pytest.raises(TraitError):
tool.userparam = "badvalue"
示例3: test_tool_html_rep
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_tool_html_rep():
""" check that the HTML rep for Jupyter notebooks works"""
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
class MyTool2(Tool):
""" A docstring description"""
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
tool2 = MyTool2()
assert len(tool._repr_html_()) > 0
assert len(tool2._repr_html_()) > 0
示例4: test_tool_exit_code
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_tool_exit_code():
""" Check that we can get the full instance configuration """
from ctapipe.core.tool import run_tool
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
with pytest.raises(SystemExit) as exc:
tool.run(["--non-existent-option"])
assert exc.value.code == 1
with pytest.raises(SystemExit) as exc:
tool.run(["--MyTool.userparam=foo"])
assert exc.value.code == 1
assert run_tool(tool, ["--help"]) == 0
assert run_tool(tool, ["--non-existent-option"]) == 1
示例5: test_load_config
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_load_config(config):
assert load_config() is not None
class MyConfigurable(Configurable):
my_var = Float(0.0, config=True)
assert MyConfigurable().my_var == 0.0
c = load_config(config)
assert c.MyConfigurable.my_var == 1.0
# Create a new MyConfigurable instance.
configurable = MyConfigurable()
assert configurable.my_var == 0.0
# Load the config object.
configurable.update_config(c)
assert configurable.my_var == 1.0
示例6: test_tool_version
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_tool_version():
""" check that the tool gets an automatic version string"""
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
assert tool.version_string != ""
示例7: test_tool_current_config
# 需要導入模塊: import traitlets [as 別名]
# 或者: from traitlets import Float [as 別名]
def test_tool_current_config():
""" Check that we can get the full instance configuration """
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
conf1 = tool.get_current_config()
tool.userparam = -1.0
conf2 = tool.get_current_config()
assert conf1["MyTool"]["userparam"] == 5.0
assert conf2["MyTool"]["userparam"] == -1.0