Skip to content

Commit a477396

Browse files
committed
More refactoring
1 parent 6f57376 commit a477396

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

src/codemodder/codemods/test/integration_utils.py

+26-41
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ def check_dependencies_after(self):
3737

3838

3939
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+
4064
def _assert_sonar_fields(self, result):
4165
del result
4266

@@ -107,26 +131,7 @@ class BaseRemediationIntegrationTest(BaseIntegrationTestMixin):
107131

108132
@classmethod
109133
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()
130135

131136
if cls.original_code is not NotImplementedError:
132137
# Some tests are easier to understand with the expected new code provided
@@ -319,27 +324,7 @@ class BaseIntegrationTest(BaseIntegrationTestMixin, DependencyTestMixin):
319324

320325
@classmethod
321326
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()
343328
if hasattr(cls, "expected_new_code"):
344329
# Some tests are easier to understand with the expected new code provided
345330
# instead of calculated

0 commit comments

Comments
 (0)