def test_get_local_plugins_uses_cli_config(): """Verify behaviour of get_local_plugins with a specified config.""" config_obj = mock.Mock() config_finder = mock.MagicMock() config_finder.cli_config.return_value = config_obj config_obj.get.return_value = '' config.get_local_plugins(config_finder, cli_config='foo.ini') config_finder.cli_config.assert_called_once_with('foo.ini')
def test_get_local_plugins_uses_cli_config(): """Verify behaviour of get_local_plugins with a specified config.""" config_obj = mock.Mock() config_finder = mock.MagicMock() config_finder.cli_config.return_value = config_obj config_finder.ignore_config_files = False config_obj.get.return_value = "" config_file_value = "foo.ini" config_finder.config_file = config_file_value config.get_local_plugins(config_finder) config_finder.cli_config.assert_called_once_with(config_file_value)
def find_plugins(self): # type: () -> None """Find and load the plugins for this application. If :attr:`check_plugins`, or :attr:`formatting_plugins` are ``None`` then this method will update them with the appropriate plugin manager instance. Given the expense of finding plugins (via :mod:`entrypoints`) we want this to be idempotent and so only update those attributes if they are ``None``. """ if self.local_plugins is None: self.local_plugins = config.get_local_plugins( self.config_finder, self.prelim_opts.config, self.prelim_opts.isolated, ) sys.path.extend(self.local_plugins.paths) if self.check_plugins is None: self.check_plugins = plugin_manager.Checkers( self.local_plugins.extension ) if self.formatting_plugins is None: self.formatting_plugins = plugin_manager.ReportFormatters( self.local_plugins.report ) self.check_plugins.load_plugins() self.formatting_plugins.load_plugins()
def find_plugins(self): # type: () -> None """Find and load the plugins for this application. If :attr:`check_plugins`, or :attr:`formatting_plugins` are ``None`` then this method will update them with the appropriate plugin manager instance. Given the expense of finding plugins (via :mod:`entrypoints`) we want this to be idempotent and so only update those attributes if they are ``None``. """ if self.local_plugins is None: self.local_plugins = config.get_local_plugins( self.config_finder, self.prelim_opts.config, self.prelim_opts.isolated) sys.path.extend(self.local_plugins.paths) if self.check_plugins is None: self.check_plugins = plugin_manager.Checkers( self.local_plugins.extension) if self.formatting_plugins is None: self.formatting_plugins = plugin_manager.ReportFormatters( self.local_plugins.report) self.check_plugins.load_plugins() self.formatting_plugins.load_plugins()
def find_plugins(self, config_file, ignore_config_files): # type: (Optional[str], bool) -> None """Find and load the plugins for this application. If :attr:`check_plugins`, or :attr:`formatting_plugins` are ``None`` then this method will update them with the appropriate plugin manager instance. Given the expense of finding plugins (via :mod:`entrypoints`) we want this to be idempotent and so only update those attributes if they are ``None``. :param str config_file: The optional configuraiton file to override all other configuration files (i.e., the --config option). :param bool ignore_config_files: Determine whether to parse configuration files or not. (i.e., the --isolated option). """ if self.local_plugins is None: self.local_plugins = config.get_local_plugins( self.config_finder, config_file, ignore_config_files) sys.path.extend(self.local_plugins.paths) if self.check_plugins is None: self.check_plugins = plugin_manager.Checkers( self.local_plugins.extension) if self.formatting_plugins is None: self.formatting_plugins = plugin_manager.ReportFormatters( self.local_plugins.report) self.check_plugins.load_plugins() self.formatting_plugins.load_plugins()
def find_plugins(self, config_finder) -> None: local_plugins = get_local_plugins(config_finder) sys.path.extend(local_plugins.paths) self.check_plugins = FlakeHellCheckers( local_plugins.extension) # this line is changed self.formatting_plugins = ReportFormatters(local_plugins.report) self.check_plugins.load_plugins() self.formatting_plugins.load_plugins()
def test_get_local_plugins_respects_isolated(): """Verify behaviour of get_local_plugins with isolated=True.""" config_finder = mock.MagicMock() local_plugins = config.get_local_plugins(config_finder, isolated=True) assert local_plugins.extension == [] assert local_plugins.report == [] assert config_finder.local_configs.called is False assert config_finder.user_config.called is False
def test_get_local_plugins(): """Verify get_local_plugins returns expected plugins.""" config_fixture_path = 'tests/fixtures/config_files/local-plugin.ini' config_finder = config.ConfigFileFinder('flake8') with mock.patch.object(config_finder, 'local_config_files') as localcfs: localcfs.return_value = [config_fixture_path] local_plugins = config.get_local_plugins(config_finder) assert local_plugins.extension == ['XE = test_plugins:ExtensionTestPlugin'] assert local_plugins.report == ['XR = test_plugins:ReportTestPlugin']
def test_get_local_plugins(): """Verify get_local_plugins returns expected plugins.""" config_fixture_path = 'tests/fixtures/config_files/local-plugin.ini' config_finder = config.ConfigFileFinder('flake8', [], []) with mock.patch.object(config_finder, 'local_config_files') as localcfs: localcfs.return_value = [config_fixture_path] local_plugins = config.get_local_plugins(config_finder) assert local_plugins.extension == ['XE = test_plugins:ExtensionTestPlugin'] assert local_plugins.report == ['XR = test_plugins:ReportTestPlugin']
def find_plugins(self): # type: () -> None if self.local_plugins is None: self.local_plugins = get_local_plugins( self.config_finder, self.prelim_opts.config, self.prelim_opts.isolated, ) sys.path.extend(self.local_plugins.paths) if self.check_plugins is None: self.check_plugins = FlakeHellCheckers( self.local_plugins.extension) super().find_plugins()
def find_plugins(self, config_finder: config.ConfigFileFinder) -> None: """Find and load the plugins for this application. Set the :attr:`check_plugins` and :attr:`formatting_plugins` attributes based on the discovered plugins found. :param config.ConfigFileFinder config_finder: The finder for finding and reading configuration files. """ local_plugins = config.get_local_plugins(config_finder) sys.path.extend(local_plugins.paths) self.check_plugins = plugin_manager.Checkers(local_plugins.extension) self.formatting_plugins = plugin_manager.ReportFormatters( local_plugins.report) self.check_plugins.load_plugins() self.formatting_plugins.load_plugins()