]> git.madduck.net Git - etc/vim.git/blob - tests/test_format.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Tox has been formatted with Black 21.4b0 (#2175)
[etc/vim.git] / tests / test_format.py
1 from unittest.mock import patch
2
3 import black
4 from parameterized import parameterized
5
6 from tests.util import (
7     BlackBaseTestCase,
8     fs,
9     ff,
10     DEFAULT_MODE,
11     dump_to_stderr,
12     read_data,
13     THIS_DIR,
14 )
15
16 SIMPLE_CASES = [
17     "beginning_backslash",
18     "bracketmatch",
19     "class_blank_parentheses",
20     "class_methods_new_line",
21     "collections",
22     "comments",
23     "comments2",
24     "comments3",
25     "comments4",
26     "comments5",
27     "comments6",
28     "comments_non_breaking_space",
29     "comment_after_escaped_newline",
30     "composition",
31     "composition_no_trailing_comma",
32     "docstring",
33     "empty_lines",
34     "expression",
35     "fmtonoff",
36     "fmtonoff2",
37     "fmtonoff3",
38     "fmtonoff4",
39     "fmtskip",
40     "fmtskip2",
41     "fmtskip3",
42     "fmtskip4",
43     "fmtskip5",
44     "fstring",
45     "function",
46     "function2",
47     "function_trailing_comma",
48     "import_spacing",
49     "numeric_literals_py2",
50     "python2",
51     "python2_unicode_literals",
52     "remove_parens",
53     "slices",
54     "string_prefixes",
55     "tricky_unicode_symbols",
56     "tupleassign",
57 ]
58
59 EXPERIMENTAL_STRING_PROCESSING_CASES = [
60     "cantfit",
61     "comments7",
62     "long_strings",
63     "long_strings__edge_case",
64     "long_strings__regression",
65     "percent_precedence",
66 ]
67
68
69 SOURCES = [
70     "tests/test_black.py",
71     "tests/test_format.py",
72     "tests/test_blackd.py",
73     "src/black/__init__.py",
74     "src/blib2to3/pygram.py",
75     "src/blib2to3/pytree.py",
76     "src/blib2to3/pgen2/conv.py",
77     "src/blib2to3/pgen2/driver.py",
78     "src/blib2to3/pgen2/grammar.py",
79     "src/blib2to3/pgen2/literals.py",
80     "src/blib2to3/pgen2/parse.py",
81     "src/blib2to3/pgen2/pgen.py",
82     "src/blib2to3/pgen2/tokenize.py",
83     "src/blib2to3/pgen2/token.py",
84     "setup.py",
85 ]
86
87
88 class TestSimpleFormat(BlackBaseTestCase):
89     @parameterized.expand(SIMPLE_CASES)
90     @patch("black.dump_to_file", dump_to_stderr)
91     def test_simple_format(self, filename: str) -> None:
92         self.check_file(filename, DEFAULT_MODE)
93
94     @parameterized.expand(EXPERIMENTAL_STRING_PROCESSING_CASES)
95     @patch("black.dump_to_file", dump_to_stderr)
96     def test_experimental_format(self, filename: str) -> None:
97         self.check_file(filename, black.Mode(experimental_string_processing=True))
98
99     @parameterized.expand(SOURCES)
100     @patch("black.dump_to_file", dump_to_stderr)
101     def test_source_is_formatted(self, filename: str) -> None:
102         path = THIS_DIR.parent / filename
103         self.check_file(str(path), DEFAULT_MODE, data=False)
104         self.assertFalse(ff(path))
105
106     def check_file(self, filename: str, mode: black.Mode, *, data: bool = True) -> None:
107         source, expected = read_data(filename, data=data)
108         actual = fs(source, mode=mode)
109         self.assertFormatEqual(expected, actual)
110         black.assert_equivalent(source, actual)
111         black.assert_stable(source, actual, mode)