File: test_exceptions.py

package info (click to toggle)
python-flake8 7.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,212 kB
  • sloc: python: 6,592; sh: 21; makefile: 19
file content (36 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Tests for the flake8.exceptions module."""
from __future__ import annotations

import pickle

import pytest

from flake8 import exceptions


@pytest.mark.parametrize(
    "err",
    (
        exceptions.FailedToLoadPlugin(
            plugin_name="plugin_name",
            exception=ValueError("boom!"),
        ),
        exceptions.PluginRequestedUnknownParameters(
            plugin_name="plugin_name",
            exception=ValueError("boom!"),
        ),
        exceptions.PluginExecutionFailed(
            filename="filename.py",
            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)