How to use the sacred.config.signature.Signature function in sacred

To help you get started, we’ve selected a few sacred examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_with_kwargs_for_posargs_does_not_raise():
    Signature(bariza).construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2, 'd': 6}, {})
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_with_kwargswildcard_doesnt_raise():
    kwargs = {'zimbabwe': 23}
    Signature(__double_underscore__).construct_arguments([1, 2], kwargs, {})
    Signature(FunCTIonWithCAPItals).construct_arguments(
        [1, 2, 3], kwargs, {})
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_constructor_extract_function_name(function, name):
        s = Signature(function)
        assert s.name == name
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_unicode_(func, expected):
    assert str(Signature(func)) == expected
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_does_not_overwrite_args_and_kwargs():
    s = Signature(bariza)
    args, kwargs = s.construct_arguments([1, 2], {'c': 3},
                                         {'a': 6, 'b': 6, 'c': 6})
    assert args == [1, 2]
    assert kwargs == {'c': 3}
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_unicode_special():
    str_signature = "complex_function_name(a=5, b='fo', c=9)"
    assert str_signature in str(Signature(complex_function_name))
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_completes_kwargs_from_options():
    s = Signature(bariza)
    args, kwargs = s.construct_arguments([2, 4], {}, {"c": 6})
    assert args == [2, 4]
    assert kwargs == {"c": 6}
    s = Signature(complex_function_name)
    args, kwargs = s.construct_arguments([], {"c": 6, "b": 7}, {"a": 1})
    assert args == []
    assert kwargs == {"a": 1, "c": 6, "b": 7}

    s = Signature(_name_with_underscore_)
    args, kwargs = s.construct_arguments([], {}, {"fo": 7, "bar": 6})
    assert args == []
    assert kwargs == {"fo": 7, "bar": 6}
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_with_duplicate_args_raises_typeerror():
    multiple_values = re.compile(".*multiple values.*")
    with pytest.raises(TypeError) as excinfo:
        s = Signature(bariza)
        s.construct_arguments([1, 2, 3], {'a': 4, 'b': 5}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(complex_function_name)
        s.construct_arguments([1], {'a': 4}, {})
    assert multiple_values.match(excinfo.value.args[0])
    with pytest.raises(TypeError) as excinfo:
        s = Signature(FunCTIonWithCAPItals)
        s.construct_arguments([1, 2, 3], {'c': 6}, {})
    assert multiple_values.match(excinfo.value.args[0])
github IDSIA / sacred / tests / test_config / test_signature.py View on Github external
def test_construct_arguments_with_expected_kwargs_does_not_raise():
    s = Signature(complex_function_name)
    s.construct_arguments([], {'a': 4, 'b': 3, 'c': 2}, {})
    s = Signature(FunCTIonWithCAPItals)
    s.construct_arguments([1, 2], {'c': 5}, {})
github IDSIA / sacred / sacred / experiment.py View on Github external
Decorator for adding an option hook function.

        An option hook is a function that is called right before a run
        is created. It receives (and potentially modifies) the options
        dictionary. That is, the dictionary of commandline options used for
        this run.

        Notes
        -----
        The decorated function MUST have an argument called options.

        The options also contain ``'COMMAND'`` and ``'UPDATE'`` entries,
        but changing them has no effect. Only modification on
        flags (entries starting with ``'--'``) are considered.
        """
        sig = Signature(function)
        if "options" not in sig.arguments:
            raise KeyError(
                "option_hook functions must have an argument called"
                " 'options', but got {}".format(sig.arguments)
            )
        self.option_hooks.append(function)
        return function