]> 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:

Add missing instructions to make test passed (#2100)
[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     "cantfit",
20     "class_blank_parentheses",
21     "class_methods_new_line",
22     "collections",
23     "comments",
24     "comments2",
25     "comments3",
26     "comments4",
27     "comments5",
28     "comments6",
29     "comments7",
30     "comments_non_breaking_space",
31     "comment_after_escaped_newline",
32     "composition",
33     "composition_no_trailing_comma",
34     "docstring",
35     "empty_lines",
36     "expression",
37     "fmtonoff",
38     "fmtonoff2",
39     "fmtonoff3",
40     "fmtonoff4",
41     "fmtskip",
42     "fmtskip2",
43     "fmtskip3",
44     "fmtskip4",
45     "fmtskip5",
46     "fstring",
47     "function",
48     "function2",
49     "function_trailing_comma",
50     "import_spacing",
51     "long_strings",
52     "long_strings__edge_case",
53     "long_strings__regression",
54     "numeric_literals_py2",
55     "percent_precedence",
56     "python2",
57     "python2_unicode_literals",
58     "remove_parens",
59     "slices",
60     "string_prefixes",
61     "tricky_unicode_symbols",
62     "tupleassign",
63 ]
64
65
66 SOURCES = [
67     "tests/test_black.py",
68     "tests/test_format.py",
69     "tests/test_blackd.py",
70     "src/black/__init__.py",
71     "src/blib2to3/pygram.py",
72     "src/blib2to3/pytree.py",
73     "src/blib2to3/pgen2/conv.py",
74     "src/blib2to3/pgen2/driver.py",
75     "src/blib2to3/pgen2/grammar.py",
76     "src/blib2to3/pgen2/literals.py",
77     "src/blib2to3/pgen2/parse.py",
78     "src/blib2to3/pgen2/pgen.py",
79     "src/blib2to3/pgen2/tokenize.py",
80     "src/blib2to3/pgen2/token.py",
81     "setup.py",
82 ]
83
84
85 class TestSimpleFormat(BlackBaseTestCase):
86     @parameterized.expand(SIMPLE_CASES)
87     @patch("black.dump_to_file", dump_to_stderr)
88     def test_simple_format(self, filename: str) -> None:
89         source, expected = read_data(filename)
90         actual = fs(source)
91         self.assertFormatEqual(expected, actual)
92         black.assert_equivalent(source, actual)
93         black.assert_stable(source, actual, DEFAULT_MODE)
94
95     @parameterized.expand(SOURCES)
96     @patch("black.dump_to_file", dump_to_stderr)
97     def test_source_is_formatted(self, filename: str) -> None:
98         path = THIS_DIR.parent / filename
99         source, expected = read_data(str(path), data=False)
100         actual = fs(source, mode=DEFAULT_MODE)
101         self.assertFormatEqual(expected, actual)
102         black.assert_equivalent(source, actual)
103         black.assert_stable(source, actual, DEFAULT_MODE)
104         self.assertFalse(ff(path))