Exemplo n.º 1
0
def trans(tmp_path):
    """A good plugin that uses entry points."""
    distinfo = tmp_path / "napari_language_pack_es_CO-0.1.0.dist-info"
    distinfo.mkdir()
    (distinfo / "top_level.txt").write_text('napari_language_pack_es_CO')
    (distinfo / "entry_points.txt").write_text(
        "[napari.languagepack]\nes_CO = napari_language_pack_es_CO\n"
    )
    (distinfo / "METADATA").write_text(
        "Metadata-Version: 2.1\n"
        "Name: napari-language-pack-es-CO\n"
        "Version: 0.1.0\n"
    )
    pkgdir = tmp_path / 'napari_language_pack_es_CO'
    msgs = pkgdir / 'locale' / 'es_CO' / 'LC_MESSAGES'
    msgs.mkdir(parents=True)
    (pkgdir / '__init__.py').touch()
    (msgs / "napari.po").write_text(es_CO_po)
    (msgs / "napari.mo").write_bytes(es_CO_mo)

    from napari_plugin_engine.manager import temp_path_additions

    with temp_path_additions(tmp_path):
        # Load translator and force a locale for testing
        translator._set_locale(TEST_LOCALE)
        return translator.load()
def test_temp_path():
    import sys

    orig_path = set(sys.path)

    with temp_path_additions('/path/') as pth:
        assert sys.path == pth
        assert '/path/' in sys.path

    assert set(sys.path) == orig_path
Exemplo n.º 3
0
def test_qt_plugin_list(test_plugin_manager, entrypoint_plugin):
    """Make sure the plugin list viewer works and has the test plugins."""

    with temp_path_additions(entrypoint_plugin):
        test_plugin_manager.discover(entry_point='app.plugin')
        assert 'a_plugin' in test_plugin_manager.plugins
        dialog = QtPluginTable(None, test_plugin_manager)
        assert dialog.table.rowCount() > 0
        plugins = {
            dialog.table.item(i, 0).text()
            for i in range(dialog.table.rowCount())
        }
        assert 'a_plugin' in plugins
def test_getting_errors(invalid_entrypoint_plugin, caplog):
    with temp_path_additions(invalid_entrypoint_plugin):
        import invalid_entrypoint_plugin as mod

    try:
        raise ValueError('I caused this')
    except ValueError as e:
        err = PluginError(plugin=mod, plugin_name='invalid', cause=e)
    errs = PluginError.get(plugin=mod)
    assert mod in {p.plugin for p in errs}
    errs = PluginError.get(plugin_name='invalid')
    assert 'invalid' in {p.plugin_name for p in errs}

    assert 'I caused this' in err.format()
    err.log()
    assert ' Error in plugin "invalid"' in caplog.text
def test_lazy_autodiscovery(tmp_path, add_specification, test_plugin_manager,
                            good_entrypoint_plugin):
    test_plugin_manager.discover_entry_point = 'app.plugin'
    assert test_plugin_manager.hook._needs_discovery is True
    with test_plugin_manager.discovery_blocked():

        @add_specification
        def test_specification(arg1, arg2):
            ...

    assert test_plugin_manager.hook._needs_discovery is True

    assert not test_plugin_manager.plugins
    with temp_path_additions(tmp_path):
        hook_caller = test_plugin_manager.hook.test_specification

    assert hook_caller.spec
    assert test_plugin_manager.plugins.get('good_entry')
    assert test_plugin_manager.hook._needs_discovery is False
Exemplo n.º 6
0
def test_qt_plugin_list(
    viewer_factory, test_plugin_manager, entrypoint_plugin
):
    """Make sure the plugin list viewer works and has the test plugins."""
    view, viewer = viewer_factory()
    with temp_path_additions(entrypoint_plugin):
        test_plugin_manager.discover(entry_point='app.plugin')
        assert 'a_plugin' in test_plugin_manager.plugins

        def handle_dialog():
            assert hasattr(viewer.window, '_plugin_list')
            table = viewer.window._plugin_list.table
            assert table.rowCount() > 0
            plugins = {
                table.item(i, 0).text() for i in range(table.rowCount())
            }
            assert 'a_plugin' in plugins
            viewer.window._plugin_list.close()

        QTimer.singleShot(100, handle_dialog)
        viewer.window._show_plugin_list(test_plugin_manager)
def test_plugin_meta(
    tmp_path,
    add_specification,
    test_plugin_manager,
    app_good_plugin,
    good_entrypoint_plugin,
    double_convention_plugin,
):

    test_plugin_manager.discover_entry_point = 'app.plugin'
    test_plugin_manager.discover_prefix = 'app_'

    with temp_path_additions(tmp_path):

        cnt, err = test_plugin_manager.discover()
        assert set(test_plugin_manager.plugins) == {
            'double_a',
            'double_b',
            'good_entry',
            'app_good_plugin',
        }

        versions = {
            'double_a': '3.2.1',
            'double_b': '3.2.1',
            'good_entry': '1.2.3',
            'app_good_plugin': '',
        }
        for name, plug in test_plugin_manager.plugins.items():
            assert versions[name] == get_version(plug)
            if name == 'app_good_plugin':
                # this one doesn't have any metadata.. but it will have plugin_name
                assert standard_metadata(plug) == {}
            else:
                assert get_version(plug) == standard_metadata(plug).get(
                    'version')