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 tests.util import (
 
  18     "beginning_backslash",
 
  20     "class_blank_parentheses",
 
  21     "class_methods_new_line",
 
  29     "comments_non_breaking_space",
 
  30     "comment_after_escaped_newline",
 
  32     "composition_no_trailing_comma",
 
  49     "function_trailing_comma",
 
  54     "tricky_unicode_symbols",
 
  59     "numeric_literals_py2",
 
  61     "python2_unicode_literals",
 
  64 EXPERIMENTAL_STRING_PROCESSING_CASES = [
 
  68     "long_strings__edge_case",
 
  69     "long_strings__regression",
 
  75     "src/black/__init__.py",
 
  76     "src/black/__main__.py",
 
  77     "src/black/brackets.py",
 
  79     "src/black/comments.py",
 
  80     "src/black/concurrency.py",
 
  84     "src/black/linegen.py",
 
  88     "src/black/numerics.py",
 
  89     "src/black/output.py",
 
  90     "src/black/parsing.py",
 
  91     "src/black/report.py",
 
  93     "src/black/strings.py",
 
  95     "src/blackd/__init__.py",
 
  96     "src/blib2to3/pygram.py",
 
  97     "src/blib2to3/pytree.py",
 
  98     "src/blib2to3/pgen2/conv.py",
 
  99     "src/blib2to3/pgen2/driver.py",
 
 100     "src/blib2to3/pgen2/grammar.py",
 
 101     "src/blib2to3/pgen2/literals.py",
 
 102     "src/blib2to3/pgen2/parse.py",
 
 103     "src/blib2to3/pgen2/pgen.py",
 
 104     "src/blib2to3/pgen2/tokenize.py",
 
 105     "src/blib2to3/pgen2/token.py",
 
 107     "tests/test_black.py",
 
 108     "tests/test_blackd.py",
 
 109     "tests/test_format.py",
 
 110     "tests/test_primer.py",
 
 117 @pytest.fixture(autouse=True)
 
 118 def patch_dump_to_file(request: Any) -> Iterator[None]:
 
 119     with patch("black.dump_to_file", dump_to_stderr):
 
 123 def check_file(filename: str, mode: black.Mode, *, data: bool = True) -> None:
 
 124     source, expected = read_data(filename, data=data)
 
 125     assert_format(source, expected, mode, fast=False)
 
 128 @pytest.mark.parametrize("filename", SIMPLE_CASES_PY2)
 
 130 def test_simple_format_py2(filename: str) -> None:
 
 131     check_file(filename, DEFAULT_MODE)
 
 134 @pytest.mark.parametrize("filename", SIMPLE_CASES)
 
 135 def test_simple_format(filename: str) -> None:
 
 136     check_file(filename, DEFAULT_MODE)
 
 139 @pytest.mark.parametrize("filename", EXPERIMENTAL_STRING_PROCESSING_CASES)
 
 140 def test_experimental_format(filename: str) -> None:
 
 141     check_file(filename, black.Mode(experimental_string_processing=True))
 
 144 @pytest.mark.parametrize("filename", SOURCES)
 
 145 def test_source_is_formatted(filename: str) -> None:
 
 146     path = THIS_DIR.parent / filename
 
 147     check_file(str(path), DEFAULT_MODE, data=False)
 
 155 def test_empty() -> None:
 
 156     source = expected = ""
 
 157     assert_format(source, expected)
 
 160 def test_pep_572() -> None:
 
 161     source, expected = read_data("pep_572")
 
 162     assert_format(source, expected, minimum_version=(3, 8))
 
 165 def test_pep_572_remove_parens() -> None:
 
 166     source, expected = read_data("pep_572_remove_parens")
 
 167     assert_format(source, expected, minimum_version=(3, 8))
 
 170 def test_pep_572_do_not_remove_parens() -> None:
 
 171     source, expected = read_data("pep_572_do_not_remove_parens")
 
 172     # the AST safety checks will fail, but that's expected, just make sure no
 
 173     # parentheses are touched
 
 174     assert_format(source, expected, fast=True)
 
 177 @pytest.mark.parametrize("major, minor", [(3, 9), (3, 10)])
 
 178 def test_pep_572_newer_syntax(major: int, minor: int) -> None:
 
 179     source, expected = read_data(f"pep_572_py{major}{minor}")
 
 180     assert_format(source, expected, minimum_version=(major, minor))
 
 183 def test_pep_570() -> None:
 
 184     source, expected = read_data("pep_570")
 
 185     assert_format(source, expected, minimum_version=(3, 8))
 
 188 def test_docstring_no_string_normalization() -> None:
 
 189     """Like test_docstring but with string normalization off."""
 
 190     source, expected = read_data("docstring_no_string_normalization")
 
 191     mode = replace(DEFAULT_MODE, string_normalization=False)
 
 192     assert_format(source, expected, mode)
 
 195 def test_long_strings_flag_disabled() -> None:
 
 196     """Tests for turning off the string processing logic."""
 
 197     source, expected = read_data("long_strings_flag_disabled")
 
 198     mode = replace(DEFAULT_MODE, experimental_string_processing=False)
 
 199     assert_format(source, expected, mode)
 
 202 def test_numeric_literals() -> None:
 
 203     source, expected = read_data("numeric_literals")
 
 204     mode = replace(DEFAULT_MODE, target_versions=PY36_VERSIONS)
 
 205     assert_format(source, expected, mode)
 
 208 def test_numeric_literals_ignoring_underscores() -> None:
 
 209     source, expected = read_data("numeric_literals_skip_underscores")
 
 210     mode = replace(DEFAULT_MODE, target_versions=PY36_VERSIONS)
 
 211     assert_format(source, expected, mode)
 
 215 def test_python2_print_function() -> None:
 
 216     source, expected = read_data("python2_print_function")
 
 217     mode = replace(DEFAULT_MODE, target_versions={black.TargetVersion.PY27})
 
 218     assert_format(source, expected, mode)
 
 221 def test_stub() -> None:
 
 222     mode = replace(DEFAULT_MODE, is_pyi=True)
 
 223     source, expected = read_data("stub.pyi")
 
 224     assert_format(source, expected, mode)
 
 227 def test_python38() -> None:
 
 228     source, expected = read_data("python38")
 
 229     assert_format(source, expected, minimum_version=(3, 8))
 
 232 def test_python39() -> None:
 
 233     source, expected = read_data("python39")
 
 234     assert_format(source, expected, minimum_version=(3, 9))