def test_load_default_plugins(self): default_plugin_qualnames = plugin.get_qualified_module_names( _repobee.ext.defaults) modules = plugin.load_plugin_modules(default_plugin_qualnames, allow_qualified=True) module_names = [mod.__name__ for mod in modules] assert module_names == default_plugin_qualnames
def test_load_bundled_plugins(self): """Test load the bundled plugins that are not default plugins.""" bundled_plugin_qualnames = plugin.get_qualified_module_names( _repobee.ext) bundled_plugin_names = plugin.get_module_names(_repobee.ext) modules = plugin.load_plugin_modules(bundled_plugin_names) module_names = [mod.__name__ for mod in modules] assert module_names == bundled_plugin_qualnames
def test_raises_when_loading_default_plugins_without_allow_qualified(self): """Default plugins can only be loaded by their qualified names, and it should only be allowed if allow_qualify is True. """ default_plugin_qualnames = plugin.get_qualified_module_names( _repobee.ext.defaults) with pytest.raises(exception.PluginLoadError) as exc_info: plugin.load_plugin_modules(default_plugin_qualnames) assert "failed to load plugin module" in str(exc_info.value)
def _get_core_command_actions_implemented_as_plugins() -> Set[Action]: qualnames = plugin.get_qualified_module_names(_repobee.ext.core_commands) modules = plugin.load_plugin_modules(qualnames, allow_qualified=True) plugin_classes = itertools.chain.from_iterable( map(plugin.get_plugin_classes_in_module, modules) ) actions = set() for plugin_class in plugin_classes: if issubclass(plugin_class, plug.cli.Command): actions.add(plugin_class.__settings__.action) return actions
def test_dist_plugins_are_loaded_when_dist_install(monkeypatch): dist_plugin_qualnames = plugin.get_qualified_module_names( _repobee.ext.dist) sys_args = "repobee -h".split() monkeypatch.setattr("_repobee.distinfo.DIST_INSTALL", True) with pytest.raises(SystemExit): # calling -h always causes a SystemExit main.main(sys_args, unload_plugins=False) qualnames = { p.__name__ for p in plug.manager.get_plugins() if isinstance(p, types.ModuleType) } assert qualnames.issuperset(dist_plugin_qualnames)
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
template_repo_urls="url-1 url-2 url-3".split(), assignements="1 2 3".split(), students=constants.STUDENTS, issue=constants.ISSUE, title_regex="some regex", traceback=False, ) PARSED_ARGS = argparse.Namespace( **repobee_plug.cli.CoreCommand.repos.setup.asdict(), **VALID_PARSED_ARGS) CLONE_ARGS = "clone -a week-2 -s slarse".split() module = namedtuple("module", ("name", )) DEFAULT_PLUGIN_NAMES = plugin.get_qualified_module_names(_repobee.ext.defaults) DIST_PLUGIN_NAMES = plugin.get_qualified_module_names(_repobee.ext.dist) @pytest.fixture def logger_exception_mock(mocker): return mocker.patch("repobee_plug.log.exception", autospec=True) @pytest.fixture def api_instance_mock(mocker): return MagicMock(spec="_repobee.github.GitHubAPI") @pytest.fixture def init_plugins_mock(mocker):