示例#1
0
def test_add_plugin_to_register(
    plugin_register_key: str,
    plugin: _PluginType,
    plugin_registy: MutableMapping[str, _PluginType],
):
    """Add plugin with one key"""
    add_plugin_to_registry(plugin_register_key, plugin, plugin_registy)
    assert plugin_register_key in plugin_registy
    assert plugin_registy[plugin_register_key] == plugin
示例#2
0
def test_add_plugin_to_register_existing_plugin_self():
    """Don't warn if plugin overwrites itself."""

    plugin_registry = copy(mock_registry_data_io)
    with pytest.warns(PluginOverwriteWarning,
                      match="SdtDataIo.+sdt.+SdtDataIo") as record:
        add_plugin_to_registry("sdt", SdtDataIo("sdt"), plugin_registry,
                               "set_plugin")
        assert len(record) == 0
示例#3
0
def test_add_plugin_to_register_existing_plugin():
    """Try plugin_overwrite"""

    plugin_registy = copy(mock_registry_data_io)
    with pytest.warns(PluginOverwriteWarning,
                      match="SdtDataIo.+sdt.+sdt_gta") as record:
        add_plugin_to_registry("sdt", SdtDataIo("sdt"), plugin_registy)
        assert len(record) == 1
    assert "sdt_gta" in plugin_registy
    assert plugin_registy["sdt_gta"].format == "sdt"
def register_model(model_type: str, model: type[Model]) -> None:
    """Add a model to the model registry.

    Parameters
    ----------
    model_type : str
        Name of the model under which it is registered.
    model : type[Model]
        model class to be registered.
    """
    add_plugin_to_registry(
        plugin_register_key=model_type, plugin=model, plugin_registry=__PluginRegistry.model
    )
示例#5
0
def test_add_plugin_to_register_naming_error():
    """Raise error if pluginkey contains '.'"""
    with pytest.raises(
            ValueError,
            match=(
                r"The character '\.' isn't allowed in the name of a plugin, "
                r"you provided the name 'bad\.name'."),
    ):
        add_plugin_to_registry(
            "bad.name",
            MockPlugin,
            mock_registry_model,
            "set_plugin"  # type:ignore
        )
示例#6
0
def test_add_plugin_to_register_existing_plugin():
    """Warn if different plugin overwrites existing."""

    plugin_registry = copy(mock_registry_data_io)
    with pytest.warns(PluginOverwriteWarning,
                      match="SdtDataIo.+sdt.+YmlProjectIo") as record:
        add_plugin_to_registry(
            "sdt",
            YmlProjectIo("sdt"),
            plugin_registry,  # type:ignore
            "set_plugin",
        )
        assert len(record) == 1
    assert plugin_registry[
        "glotaran.builtin.io.yml.yml.YmlProjectIo"].format == "sdt"
def register_megacomplex(megacomplex_type: str, megacomplex: type[Megacomplex]) -> None:
    """Add a megacomplex to the megacomplex registry.

    Parameters
    ----------
    megacomplex_type : str
        Name of the megacomplex under which it is registered.
    megacomplex : type[Megacomplex]
        megacomplex class to be registered.
    """
    add_plugin_to_registry(
        plugin_register_key=megacomplex_type,
        plugin=megacomplex,
        plugin_registry=__PluginRegistry.megacomplex,
        plugin_set_func_name="set_megacomplex_plugin",
    )