class TestFailedToLoadPlugin(_ExceptionTest): """Tests for the FailedToLoadPlugin exception.""" err = exceptions.FailedToLoadPlugin( plugin_name='plugin_name', exception=ValueError('boom!'), )
def load_plugin(self, verify_requirements=False): """Retrieve the plugin for this entry-point. This loads the plugin, stores it on the instance and then returns it. It does not reload it after the first time, it merely returns the cached plugin. :param bool verify_requirements: Whether or not to make setuptools verify that the requirements for the plugin are satisfied. :returns: Nothing """ if self._plugin is None: LOG.info('Loading plugin "%s" from entry-point.', self.name) try: self._load(verify_requirements) except Exception as load_exception: LOG.exception(load_exception) failed_to_load = exceptions.FailedToLoadPlugin( plugin=self, exception=load_exception, ) LOG.critical(str(failed_to_load)) raise failed_to_load
def create_plugin_mock(raise_exception=False): """Create an auto-spec'd mock of a flake8 Plugin.""" plugin = mock.create_autospec(manager.Plugin, instance=True) if raise_exception: plugin.load_plugin.side_effect = exceptions.FailedToLoadPlugin( plugin=mock.Mock(name='T101'), exception=ValueError('Test failure'), ) return plugin
class TestFailedToLoadPlugin(_ExceptionTest): """Tests for the FailedToLoadPlugin exception.""" err = exceptions.FailedToLoadPlugin( plugin=plugins_manager.Plugin( 'plugin_name', entrypoints.EntryPoint('plugin_name', 'os.path', None), ), exception=ValueError('boom!'), )
def load_plugin(self): """Retrieve the plugin for this entry-point. This loads the plugin, stores it on the instance and then returns it. It does not reload it after the first time, it merely returns the cached plugin. :returns: Nothing """ if self._plugin is None: LOG.info('Loading plugin "%s" from entry-point.', self.name) try: self._load() except Exception as load_exception: LOG.exception(load_exception) failed_to_load = exceptions.FailedToLoadPlugin( plugin=self, exception=load_exception) LOG.critical(str(failed_to_load)) raise failed_to_load
"""Tests for the flake8.exceptions module.""" import pickle import pytest from flake8 import exceptions @pytest.mark.parametrize( 'err', (exceptions.FailedToLoadPlugin( plugin_name='plugin_name', exception=ValueError('boom!'), ), exceptions.InvalidSyntax(exception=ValueError('Unexpected token: $')), exceptions.PluginRequestedUnknownParameters( plugin={'plugin_name': 'plugin_name'}, exception=ValueError('boom!'), ), exceptions.PluginExecutionFailed( plugin={'plugin_name': 'plugin_name'}, exception=ValueError('boom!'), )), ) def test_pickleable(err): """Ensure that our exceptions can cross pickle boundaries.""" for proto in range(pickle.HIGHEST_PROTOCOL + 1): new_err = pickle.loads(pickle.dumps(err, protocol=proto)) assert str(err) == str(new_err) orig_e = err.original_exception new_e = new_err.original_exception assert (type(orig_e), orig_e.args) == (type(new_e), new_e.args)
"""Tests for the flake8.exceptions module.""" import pickle import pytest from flake8 import exceptions @pytest.mark.parametrize( "err", ( exceptions.FailedToLoadPlugin( plugin_name="plugin_name", exception=ValueError("boom!"), ), exceptions.PluginRequestedUnknownParameters( plugin={"plugin_name": "plugin_name"}, exception=ValueError("boom!"), ), exceptions.PluginExecutionFailed( plugin={"plugin_name": "plugin_name"}, exception=ValueError("boom!"), ), ), ) def test_pickleable(err): """Ensure that our exceptions can cross pickle boundaries.""" for proto in range(pickle.HIGHEST_PROTOCOL + 1): new_err = pickle.loads(pickle.dumps(err, protocol=proto)) assert str(err) == str(new_err) orig_e = err.original_exception