diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 524976fb..a573aaad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,7 @@ repos: rev: ab802050e6e96aaaf7f917fcbc333bb74e2e57f7 # frozen: v1.4.2 hooks: - id: docformatter + language_version: python3.12 - repo: https://github.com/PyCQA/flake8 rev: d93590f5be797aabb60e3b09f2f52dddb02f349f # frozen: 7.3.0 hooks: diff --git a/src/mdformat/_cli.py b/src/mdformat/_cli.py index 682b7896..150668a6 100644 --- a/src/mdformat/_cli.py +++ b/src/mdformat/_cli.py @@ -326,7 +326,8 @@ def separate_core_and_plugin_opts(opts: Mapping) -> tuple[dict, dict]: class InvalidPath(Exception): """Exception raised when a path does not exist.""" - def __init__(self, path: Path): + def __init__(self, path: Path) -> None: + super().__init__(path) self.path = path diff --git a/tests/test_cli.py b/tests/test_cli.py index 28c36223..b4b5efa8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,11 +1,12 @@ import os +import pickle import sys from unittest.mock import patch import pytest import mdformat -from mdformat._cli import get_plugin_info_str, run, wrap_paragraphs +from mdformat._cli import InvalidPath, get_plugin_info_str, run, wrap_paragraphs from mdformat.plugins import CODEFORMATTERS, PARSER_EXTENSIONS from tests.utils import ( FORMATTED_MARKDOWN, @@ -92,6 +93,22 @@ def test_invalid_file(capsys): assert "does not exist" in captured.err +@pytest.mark.parametrize("use_keyword", [False, True]) +def test_invalid_path_exception(tmp_path, use_keyword): + path = tmp_path / "missing.md" + error = InvalidPath(path=path) if use_keyword else InvalidPath(path) + + assert error.path == path + assert error.args == (path,) + assert str(error) == str(path) + + restored = pickle.loads(pickle.dumps(error)) + assert isinstance(restored, InvalidPath) + assert restored.path == path + assert restored.args == error.args + assert str(restored) == str(error) + + @pytest.mark.skipif(os.name == "nt", reason="No os.mkfifo on windows") def test_fifo(tmp_path, capsys): fifo_path = tmp_path / "fifo1"