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


Python traitlets.Float方法代码示例

本文整理汇总了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 
开发者ID:cyanogen,项目名称:uchroma,代码行数:23,代码来源:led.py

示例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" 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:21,代码来源:test_tool.py

示例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 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:18,代码来源:test_tool.py

示例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 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:25,代码来源:test_tool.py

示例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 
开发者ID:cortex-lab,项目名称:phy,代码行数:21,代码来源:test_config.py

示例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 != "" 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:11,代码来源:test_tool.py

示例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 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:16,代码来源:test_tool.py


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