Exemplo n.º 1
0
def get_model(model_type: str) -> type[Model]:
    """Retrieve a model from the model registry.

    Parameters
    ----------
    model_type : str
        Name of the model under which it is registered.

    Returns
    -------
    type[Model]
        Model class
    """
    return get_plugin_from_registry(
        plugin_register_key=model_type,
        plugin_registry=__PluginRegistry.model,
        not_found_error_message=(
            f"Unknown model type {model_type!r}. Known model types are: {known_model_names()}"
        ),
    )
Exemplo n.º 2
0
def get_data_io(format_name: str) -> DataIoInterface:
    """Retrieve a data io plugin from the data_io registry.

    Parameters
    ----------
    format_name : str
        Name of the data io plugin under which it is registered.

    Returns
    -------
    DataIoInterface
        Data io plugin instance.
    """
    return get_plugin_from_registry(
        plugin_register_key=format_name,
        plugin_registry=__PluginRegistry.data_io,
        not_found_error_message=(
            f"Unknown  Data Io format {format_name!r}. Known formats are: {known_data_formats()}"
        ),
    )
Exemplo n.º 3
0
def get_megacomplex(megacomplex_type: str) -> type[Megacomplex]:
    """Retrieve a megacomplex from the megacomplex registry.

    Parameters
    ----------
    megacomplex_type : str
        Name of the megacomplex under which it is registered.

    Returns
    -------
    type[Megacomplex]
        Megacomplex class
    """
    return get_plugin_from_registry(
        plugin_register_key=megacomplex_type,
        plugin_registry=__PluginRegistry.megacomplex,
        not_found_error_message=(
            f"Unknown megacomplex type {megacomplex_type!r}. "
            f"Known megacomplex types are: {known_megacomplex_names(full_names=True)}"
        ),
    )
Exemplo n.º 4
0
def test_get_plugin_from_register_not_found():
    """Error when Plugin wasn't found"""
    with pytest.raises(ValueError, match="something went wrong"):
        get_plugin_from_registry("not-registered", mock_registry_data_io,
                                 "something went wrong")
Exemplo n.º 5
0
def test_get_plugin_from_register():
    """Retrieve plugin from registry"""
    plugin = get_plugin_from_registry("sdt", mock_registry_data_io,
                                      "something went wrong")
    assert plugin.format == "sdt"