| 143 | |
| 144 | |
| 145 | def process(entry): |
| 146 | fname, class_name, method_name, class_children, method_children = entry |
| 147 | if method_children > class_children / 2: |
| 148 | return |
| 149 | if method_children < 250: |
| 150 | return |
| 151 | |
| 152 | fname = Path(fname) |
| 153 | if "test" in fname.stem: |
| 154 | return |
| 155 | |
| 156 | print(f"{fname} {class_name} {method_name} {class_children} {method_children}") |
| 157 | |
| 158 | dname = Path("tmp.benchmarks/refactor-benchmark-spyder") |
| 159 | dname.mkdir(exist_ok=True) |
| 160 | |
| 161 | dname = dname / f"{fname.stem}_{class_name}_{method_name}" |
| 162 | dname.mkdir(exist_ok=True) |
| 163 | |
| 164 | shutil.copy(fname, dname / fname.name) |
| 165 | |
| 166 | docs_dname = dname / ".docs" |
| 167 | docs_dname.mkdir(exist_ok=True) |
| 168 | |
| 169 | ins_fname = docs_dname / "instructions.md" |
| 170 | ins_fname.write_text(f"""# Refactor {class_name}.{method_name} |
| 171 | |
| 172 | Refactor the `{method_name}` method in the `{class_name}` class to be a stand alone, top level function. |
| 173 | Name the new function `{method_name}`, exactly the same name as the existing method. |
| 174 | Update any existing `self.{method_name}` calls to work with the new `{method_name}` function. |
| 175 | """) # noqa: E501 |
| 176 | |
| 177 | test_fname = dname / f"{fname.stem}_test.py" |
| 178 | test_fname.write_text(f""" |
| 179 | import unittest |
| 180 | from benchmark.refactor_tools import verify_refactor |
| 181 | from pathlib import Path |
| 182 | |
| 183 | class TheTest(unittest.TestCase): |
| 184 | def test_{method_name}(self): |
| 185 | fname = Path(__file__).parent / "{fname.name}" |
| 186 | method = "{method_name}" |
| 187 | method_children = {method_children} |
| 188 | |
| 189 | class_name = "{class_name}" |
| 190 | class_children = {class_children} |
| 191 | |
| 192 | verify_refactor(fname, method, method_children, class_name, class_children) |
| 193 | |
| 194 | if __name__ == "__main__": |
| 195 | unittest.main() |
| 196 | """) |
| 197 | |
| 198 | |
| 199 | def main(paths): |