-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_fix_mutable_params.py
More file actions
45 lines (34 loc) · 1.26 KB
/
test_fix_mutable_params.py
File metadata and controls
45 lines (34 loc) · 1.26 KB
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
from codemodder.codemods.test import BaseIntegrationTest
from core_codemods.fix_mutable_params import (
FixMutableParams,
FixMutableParamsTransformer,
)
class TestFixMutableParams(BaseIntegrationTest):
codemod = FixMutableParams
original_code = """
def foo(x, y=[]):
y.append(x)
print(y)
def bar(x="hello"):
print(x)
def baz(x={"foo": 42}, y=set()):
print(x)
print(y)
"""
expected_new_code = """
def foo(x, y=None):
y = [] if y is None else y
y.append(x)
print(y)
def bar(x="hello"):
print(x)
def baz(x=None, y=None):
x = {"foo": 42} if x is None else x
y = set() if y is None else y
print(x)
print(y)
"""
expected_diff = '--- \n+++ \n@@ -1,4 +1,5 @@\n-def foo(x, y=[]):\n+def foo(x, y=None):\n+ y = [] if y is None else y\n y.append(x)\n print(y)\n \n@@ -7,6 +8,8 @@\n print(x)\n \n \n-def baz(x={"foo": 42}, y=set()):\n+def baz(x=None, y=None):\n+ x = {"foo": 42} if x is None else x\n+ y = set() if y is None else y\n print(x)\n print(y)'
expected_line_change = 1
num_changes = 2
change_description = FixMutableParamsTransformer.change_description