summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-02-19 08:38:37 -0800
committerAnthony Sottile <asottile@umich.edu>2019-02-19 08:38:37 -0800
commite8de066f9411d320e31ca0ecb081114f01083434 (patch)
treefaac2bf4c020cc96a62fdbd5f1e056cd3e4622d0 /tests
parent9b770f590ecca6e5d2e1c50ad707337e6695cfd4 (diff)
downloadflake8-e8de066f9411d320e31ca0ecb081114f01083434.tar.gz
Ensure exceptions are pickleable
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_exceptions.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
new file mode 100644
index 0000000..4766b78
--- /dev/null
+++ b/tests/unit/test_exceptions.py
@@ -0,0 +1,54 @@
+"""Tests for the flake8.exceptions module."""
+import pickle
+
+import entrypoints
+
+from flake8 import exceptions
+from flake8.plugins import manager as plugins_manager
+
+
+class _ExceptionTest:
+ def test_pickleable(self):
+ """Test that the exception is round-trip pickleable."""
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ new_err = pickle.loads(pickle.dumps(self.err, protocol=proto))
+ assert str(self.err) == str(new_err)
+ orig_e = self.err.original_exception
+ new_e = new_err.original_exception
+ assert (type(orig_e), orig_e.args) == (type(new_e), new_e.args)
+
+
+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!'),
+ )
+
+
+class TestInvalidSyntax(_ExceptionTest):
+ """Tests for the InvalidSyntax exception."""
+
+ err = exceptions.InvalidSyntax(exception=ValueError('Unexpected token: $'))
+
+
+class TestPluginRequestedUnknownParameters(_ExceptionTest):
+ """Tests for the PluginRequestedUnknownParameters exception."""
+
+ err = exceptions.PluginRequestedUnknownParameters(
+ plugin={'plugin_name': 'plugin_name'},
+ exception=ValueError('boom!'),
+ )
+
+
+class TestPluginExecutionFailed(_ExceptionTest):
+ """Tests for the PluginExecutionFailed exception."""
+
+ err = exceptions.PluginExecutionFailed(
+ plugin={'plugin_name': 'plugin_name'},
+ exception=ValueError('boom!'),
+ )