Exemplo n.º 1
0
def test_get_method_from_plugin_just_attribute():
    """Error if attribute does exists on plugin but is not a method."""
    plugin = MockPlugin()

    with pytest.raises(
            ValueError,
            match=r"The plugin '.+?\.MockPlugin' has no method 'format_name'"):
        get_method_from_plugin(plugin, "format_name")
Exemplo n.º 2
0
def test_get_method_from_plugin_missing_attribute():
    """Error if attribute does not exists on plugin."""
    plugin = MockPlugin()

    with pytest.raises(
            ValueError,
            match=
            r"The plugin '.+?\.MockPlugin' has no method 'not_even_an_attribute'"
    ):
        get_method_from_plugin(plugin, "not_even_an_attribute")
Exemplo n.º 3
0
def test_get_method_from_plugin():
    """Method works like a function."""
    plugin = MockPlugin()

    method = get_method_from_plugin(plugin, "some_method")

    assert method() == "got the method of mock"
def get_project_io_method(format_name: str,
                          method_name: ProjectIoMethods) -> Callable[..., Any]:
    """Retrieve implementation of project io functionality for the format 'format_name'.

    This allows to get the proper help and autocomplete for the function,
    which is especially valuable if the function provides additional options.

    Parameters
    ----------
    format_name : str
        Format the dataloader should be able to read.
    method_name : {'load_model', 'write_model', 'load_parameters', 'write_parameters',\
    'load_scheme', 'write_scheme', 'load_result', 'write_result'}
        Method name, e.g. load_model.

    Returns
    -------
    Callable[..., Any]
        The function which is called in the background by the convenience functions.


    .. # noqa: DAR103 method_name
    """
    io = get_project_io(format_name)
    return get_method_from_plugin(io, method_name)
Exemplo n.º 5
0
def get_datasaver(format_name: str) -> DataSaver:
    """Retrieve implementation of the ``save_dataset`` functionality for the format 'format_name'.

    This allows to get the proper help and autocomplete for the function,
    which is especially valuable if the function provides additional options.

    Parameters
    ----------
    format_name : str
        Format the datawriter should be able to write.

    Returns
    -------
    DataSaver
        Function to write :xarraydoc:`Dataset` to the format ``format_name`` .
    """
    io = get_data_io(format_name)
    return get_method_from_plugin(io, "save_dataset")