コード例 #1
0
    def test_raises_on_filepath_by_default(self, tmpdir):
        plugin_file = pathlib.Path(str(tmpdir)) / "pylint.py"
        shutil.copy(_repobee.ext.javac.__file__, str(plugin_file))

        with pytest.raises(exception.PluginLoadError) as exc_info:
            plugin.initialize_plugins([str(plugin_file)])

        assert "Filepaths not allowed" in str(exc_info.value)
コード例 #2
0
def _initialize_non_default_plugins(plugin_names: List[str]) -> None:
    if distinfo.DIST_INSTALL:
        plug.log.debug("Initializing active plugins")
        plugin.initialize_plugins(disthelpers.get_active_plugins(),
                                  allow_filepath=True)

    plug.log.debug("Initializing preparser-specified plugins")
    plugin.initialize_plugins(plugin_names, allow_filepath=True)
コード例 #3
0
    def test_raises_when_filepath_is_not_python_module(self, tmpdir):
        not_a_python_module = pathlib.Path(str(tmpdir)) / "some_file.txt"
        not_a_python_module.write_text(
            "This is definitely\nnot a Python module")

        with pytest.raises(exception.PluginLoadError) as exc_info:
            plugin.initialize_plugins([str(not_a_python_module)],
                                      allow_filepath=True)

        assert f"failed to load plugin module {not_a_python_module}" in str(
            exc_info.value)
コード例 #4
0
    def test_initialize_from_filepath_filepath(self, tmpdir):
        """Test initializing a plugin that's specified by a filepath."""
        plugin_file = pathlib.Path(str(tmpdir)) / "pylint.py"
        shutil.copy(_repobee.ext.pylint.__file__, str(plugin_file))

        initialized_plugins = plugin.initialize_plugins([str(plugin_file)],
                                                        allow_filepath=True)

        assert len(initialized_plugins) == 1
        assert initialized_plugins[0].__file__ == str(plugin_file)
コード例 #5
0
def _initialize_plugins(parsed_preparser_args: argparse.Namespace) -> None:
    # IMPORTANT: the default plugins must be loaded before user-defined
    # plugins to ensure that the user-defined plugins override the defaults
    # in firstresult hooks
    plug.log.debug("Initializing default plugins")
    plugin.initialize_default_plugins()

    if distinfo.DIST_INSTALL:
        plug.log.debug("Initializing dist plugins")
        plugin.initialize_dist_plugins()

    if not parsed_preparser_args.no_plugins:
        if distinfo.DIST_INSTALL:
            plug.log.debug("Initializing active plugins")
            plugin.initialize_plugins(disthelpers.get_active_plugins(),
                                      allow_filepath=True)

        plug.log.debug("Initializing preparser-specified plugins")
        plugin_names = parsed_preparser_args.plug or []
        plugin.initialize_plugins(plugin_names, allow_filepath=True)
コード例 #6
0
    def test_deprecation_warning_is_emitted_for_deprecated_hook(
            self, monkeypatch):
        deprecated_hook = "clone_parser_hook"
        assert (deprecated_hook in plug.deprecated_hooks()
                ), "hook used here must actually be deprecated"

        # dynamically create a module with a deprecated hook function
        @plug.repobee_hook
        def clone_parser_hook(self, clone_parser):
            pass

        mod_name = "repobee-deprecation-test-plugin"
        mod = types.ModuleType(mod_name)
        mod.__dict__[deprecated_hook] = clone_parser_hook

        monkeypatch.setattr
        with patch(
                "_repobee.plugin.load_plugin_modules",
                autospec=True,
                return_value=[mod],
        ), patch("repobee_plug.log.warning", autospec=True) as warning_mock:
            plugin.initialize_plugins([mod_name])

        assert warning_mock.called
コード例 #7
0
def test_invalid_plug_options(dispatch_command_mock, init_plugins_mock):
    """-f is not a valid option for plugins and should be bumped to the
    main parser

    Note that the default plugins must be loaded for this test to work.
    """
    plugin.initialize_plugins(
        plugin.get_qualified_module_names(_repobee.ext.defaults),
        allow_qualified=True,
    )

    sys_args = ["repobee", "-p", "javac", "-f", *CLONE_ARGS]

    with pytest.raises(SystemExit):
        main.main(sys_args)

    init_plugins_mock.assert_has_calls(
        [
            call(["javac"], allow_filepath=True),
            call(DEFAULT_PLUGIN_NAMES, allow_qualified=True),
        ],
        any_order=True,
    )
    assert not dispatch_command_mock.called
コード例 #8
0
    def test_raises_on_qualified_names_by_default(self):
        qualname = "_repobee.ext.query"
        with pytest.raises(exception.PluginLoadError) as exc_info:
            plugin.initialize_plugins([qualname])

        assert "Qualified names not allowed" in str(exc_info.value)