Coverage for src/renaissance/recipes/simplify_renaissance.py: 100%
17 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 10:34 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 10:34 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""AI: Recipe that simplifies Renaissance's own unit-to-pytest conversion files."""
9from pathlib import Path
10from typing import override
12from renaissance.recipes.python_refactoring import PythonRefactoring
15class SimplifyRenaissance(PythonRefactoring):
16 """AI: Recipe that simplifies Renaissance's own unit-to-pytest conversion files."""
18 def __init__(self, file) -> None:
19 """AI: Prepare a refactoring processor scoped to Renaissance's own unit-to-pytest conversion files."""
20 super().__init__(file)
21 self.white_list_pattern = "unit_to_pytest"
22 self.black_list_pattern = "SimplifyRenaissance"
24 @override
25 def run(self) -> None:
26 if self.black_list_pattern in self.filename or self.white_list_pattern not in self.filename:
27 print(f"skipping: {Path(self.filename).resolve()}")
28 return
30 print(f"simplify {Path(self.filename).resolve()}")
31 self.replace_stmt("$val = match.expansions[$key][0].signature", "$val= match[$key]")
32 self.replace_stmt(
33 "factory = ASTFactory(PythonASTNode)\n$atu = factory.create_from_text($code, $name)",
34 "PythonASTNode.load_from_text($code, $name)",
35 )
36 self.commit()