Ejemplo n.º 1
0
class TestPluginRequestedUnknownParameters(_ExceptionTest):
    """Tests for the PluginRequestedUnknownParameters exception."""

    err = exceptions.PluginRequestedUnknownParameters(
        plugin={'plugin_name': 'plugin_name'},
        exception=ValueError('boom!'),
    )
Ejemplo n.º 2
0
 def run_check(self, plugin, **arguments):
     """Run the check in a single plugin."""
     LOG.debug("Running %r with %r", plugin, arguments)
     try:
         self.processor.keyword_arguments_for(
             plugin["parameters"], arguments
         )
     except AttributeError as ae:
         LOG.error("Plugin requested unknown parameters.")
         raise exceptions.PluginRequestedUnknownParameters(
             plugin=plugin, exception=ae
         )
     return plugin["plugin"](**arguments)
Ejemplo n.º 3
0
 def run_check(self, plugin, **arguments):
     """Run the check in a single plugin."""
     LOG.debug("Running %r with %r", plugin, arguments)
     try:
         self.processor.keyword_arguments_for(plugin["parameters"],
                                              arguments)
     except AttributeError as ae:
         LOG.error("Plugin requested unknown parameters.")
         raise exceptions.PluginRequestedUnknownParameters(plugin=plugin,
                                                           exception=ae)
     try:
         return plugin["plugin"](**arguments)
     except Exception as all_exc:
         LOG.critical("Plugin %s raised an unexpected exception",
                      plugin["name"])
         raise exceptions.PluginExecutionFailed(plugin=plugin,
                                                excetion=all_exc)
Ejemplo n.º 4
0
 def run_check(self, plugin, **arguments):
     """Run the check in a single plugin."""
     LOG.debug('Running %r with %r', plugin, arguments)
     try:
         self.processor.keyword_arguments_for(
             plugin['parameters'],
             arguments,
         )
     except AttributeError as ae:
         LOG.error('Plugin requested unknown parameters.')
         raise exceptions.PluginRequestedUnknownParameters(
             plugin=plugin,
             exception=ae,
         )
     try:
         return plugin['plugin'](**arguments)
     except Exception as all_exc:
         LOG.critical('Plugin %s raised an unexpected exception',
                      plugin['name'])
         raise exceptions.PluginExecutionFailed(
             plugin=plugin,
             excetion=all_exc,
         )
Ejemplo n.º 5
0
"""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)
Ejemplo n.º 6
0
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
        new_e = new_err.original_exception
        assert (type(orig_e), orig_e.args) == (type(new_e), new_e.args)