Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/mdformat/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
19 changes: 18 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"
Expand Down