Python traitlets.Float() Examples

The following are 7 code examples of traitlets.Float(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module traitlets , or try the search function .
Example #1
Source File: led.py    From uchroma with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: test_tool.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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" 
Example #3
Source File: test_tool.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #4
Source File: test_tool.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #5
Source File: test_config.py    From phy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #6
Source File: test_tool.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 != "" 
Example #7
Source File: test_tool.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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