@@ -37,6 +37,30 @@ def check_dependencies_after(self):
37
37
38
38
39
39
class BaseIntegrationTestMixin :
40
+
41
+ @classmethod
42
+ def setup_class (cls ):
43
+ codemod_id = (
44
+ cls .codemod ().id if isinstance (cls .codemod , type ) else cls .codemod .id
45
+ )
46
+ cls .codemod_instance = validate_codemod_registration (codemod_id )
47
+
48
+ cls .output_path = tempfile .mkstemp ()[1 ]
49
+ cls .code_dir = tempfile .mkdtemp ()
50
+
51
+ if not hasattr (cls , "code_filename" ):
52
+ # Only a few codemods require the analyzed file to have a specific filename
53
+ # All others can just be `code.py`
54
+ cls .code_filename = "code.py"
55
+
56
+ cls .code_path = os .path .join (cls .code_dir , cls .code_filename )
57
+
58
+ if cls .code_filename == "settings.py" and "Django" in str (cls ):
59
+ # manage.py must be in the directory above settings.py for this codemod to run
60
+ parent_dir = Path (cls .code_dir ).parent
61
+ manage_py_path = parent_dir / "manage.py"
62
+ manage_py_path .touch ()
63
+
40
64
def _assert_sonar_fields (self , result ):
41
65
del result
42
66
@@ -107,26 +131,7 @@ class BaseRemediationIntegrationTest(BaseIntegrationTestMixin):
107
131
108
132
@classmethod
109
133
def setup_class (cls ):
110
- codemod_id = (
111
- cls .codemod ().id if isinstance (cls .codemod , type ) else cls .codemod .id
112
- )
113
- cls .codemod_instance = validate_codemod_registration (codemod_id )
114
-
115
- cls .output_path = tempfile .mkstemp ()[1 ]
116
- cls .code_dir = tempfile .mkdtemp ()
117
-
118
- if not hasattr (cls , "code_filename" ):
119
- # Only a few codemods require the analyzed file to have a specific filename
120
- # All others can just be `code.py`
121
- cls .code_filename = "code.py"
122
-
123
- cls .code_path = os .path .join (cls .code_dir , cls .code_filename )
124
-
125
- if cls .code_filename == "settings.py" and "Django" in str (cls ):
126
- # manage.py must be in the directory above settings.py for this codemod to run
127
- parent_dir = Path (cls .code_dir ).parent
128
- manage_py_path = parent_dir / "manage.py"
129
- manage_py_path .touch ()
134
+ super ().setup_class ()
130
135
131
136
if cls .original_code is not NotImplementedError :
132
137
# Some tests are easier to understand with the expected new code provided
@@ -319,27 +324,7 @@ class BaseIntegrationTest(BaseIntegrationTestMixin, DependencyTestMixin):
319
324
320
325
@classmethod
321
326
def setup_class (cls ):
322
- codemod_id = (
323
- cls .codemod ().id if isinstance (cls .codemod , type ) else cls .codemod .id
324
- )
325
- cls .codemod_instance = validate_codemod_registration (codemod_id )
326
-
327
- cls .output_path = tempfile .mkstemp ()[1 ]
328
- cls .code_dir = tempfile .mkdtemp ()
329
-
330
- if not hasattr (cls , "code_filename" ):
331
- # Only a few codemods require the analyzed file to have a specific filename
332
- # All others can just be `code.py`
333
- cls .code_filename = "code.py"
334
-
335
- cls .code_path = os .path .join (cls .code_dir , cls .code_filename )
336
-
337
- if cls .code_filename == "settings.py" and "Django" in str (cls ):
338
- # manage.py must be in the directory above settings.py for this codemod to run
339
- parent_dir = Path (cls .code_dir ).parent
340
- manage_py_path = parent_dir / "manage.py"
341
- manage_py_path .touch ()
342
-
327
+ super ().setup_class ()
343
328
if hasattr (cls , "expected_new_code" ):
344
329
# Some tests are easier to understand with the expected new code provided
345
330
# instead of calculated
0 commit comments