-
Notifications
You must be signed in to change notification settings - Fork 183
/
test_add_trailing_commas.py
90 lines (73 loc) · 2.05 KB
/
test_add_trailing_commas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
from libcst.codemod import CodemodTest
from libcst.codemod.commands.add_trailing_commas import AddTrailingCommas
class AddTrailingCommasTest(CodemodTest):
TRANSFORM = AddTrailingCommas
def test_transform_defines(self) -> None:
before = """
def f(x, y):
pass
"""
after = """
def f(x, y,):
pass
"""
self.assertCodemod(before, after)
def test_skip_transforming_defines(self) -> None:
before = """
# skip defines with no params.
def f0():
pass
# skip defines with a single param named `self`.
class Foo:
def __init__(self):
pass
"""
after = before
self.assertCodemod(before, after)
def test_transform_calls(self) -> None:
before = """
f(a, b, c)
g(x=a, y=b, z=c)
"""
after = """
f(a, b, c,)
g(x=a, y=b, z=c,)
"""
self.assertCodemod(before, after)
def test_skip_transforming_calls(self) -> None:
before = """
# skip empty calls
f()
# skip calls with one argument
g(a)
g(x=a)
"""
after = before
self.assertCodemod(before, after)
def test_using_yapf_presets(self) -> None:
before = """
def f(x): # skip single parameters for yapf
pass
def g(x, y):
pass
"""
after = """
def f(x): # skip single parameters for yapf
pass
def g(x, y,):
pass
"""
self.assertCodemod(before, after, formatter="yapf")
def test_using_custom_presets(self) -> None:
before = """
def f(x, y, z):
pass
f(5, 6, 7)
"""
after = before
self.assertCodemod(before, after, parameter_count=4, argument_count=4)