All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 from dataclasses import replace
2 from typing import Any, Iterator
3 from unittest.mock import patch
8 from black.mode import TargetVersion
9 from tests.util import (
18 @pytest.fixture(autouse=True)
19 def patch_dump_to_file(request: Any) -> Iterator[None]:
20 with patch("black.dump_to_file", dump_to_stderr):
24 def check_file(subdir: str, filename: str, *, data: bool = True) -> None:
25 args, source, expected = read_data_with_mode(subdir, filename, data=data)
31 minimum_version=args.minimum_version,
33 if args.minimum_version is not None:
34 major, minor = args.minimum_version
35 target_version = TargetVersion[f"PY{major}{minor}"]
36 mode = replace(args.mode, target_versions={target_version})
38 source, expected, mode, fast=args.fast, minimum_version=args.minimum_version
42 @pytest.mark.filterwarnings("ignore:invalid escape sequence.*:DeprecationWarning")
43 @pytest.mark.parametrize("filename", all_data_cases("cases"))
44 def test_simple_format(filename: str) -> None:
45 check_file("cases", filename)
53 def test_empty() -> None:
54 source = expected = ""
55 assert_format(source, expected)
58 def test_patma_invalid() -> None:
59 source, expected = read_data("miscellaneous", "pattern_matching_invalid")
60 mode = black.Mode(target_versions={black.TargetVersion.PY310})
61 with pytest.raises(black.parsing.InvalidInput) as exc_info:
62 assert_format(source, expected, mode, minimum_version=(3, 10))
64 exc_info.match("Cannot parse: 10:11")