Skip to content

Commit 3f6547d

Browse files
committed
compile regex pattern
1 parent c2d494f commit 3f6547d

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from codeflash.cli_cmds.console import logger
1616
from codeflash.code_utils.config_parser import find_pyproject_toml
1717

18+
ImportErrorPattern = re.compile(r"^.*ModuleNotFoundError.*$", re.MULTILINE)
19+
1820

1921
@contextmanager
2022
def custom_addopts() -> None:

codeflash/optimization/function_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ast
44
import concurrent.futures
55
import os
6-
import re
76
import subprocess
87
import time
98
import uuid
@@ -24,6 +23,7 @@
2423
from codeflash.code_utils import env_utils
2524
from codeflash.code_utils.code_replacer import replace_function_definitions_in_module
2625
from codeflash.code_utils.code_utils import (
26+
ImportErrorPattern,
2727
cleanup_paths,
2828
file_name_from_test_module_name,
2929
get_run_tmp_file,
@@ -1196,7 +1196,7 @@ def run_and_parse_tests(
11961196
if "ModuleNotFoundError" in run_result.stdout:
11971197
from rich.text import Text
11981198

1199-
match = re.search(r"^.*ModuleNotFoundError.*$", run_result.stdout, re.MULTILINE).group()
1199+
match = ImportErrorPattern.search(run_result.stdout).group()
12001200
panel = Panel(Text.from_markup(f"⚠️ {match} ", style="bold red"), expand=False)
12011201
console.print(panel)
12021202
if testing_type in {TestingMode.BEHAVIOR, TestingMode.PERFORMANCE}:

tests/test_test_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
from pathlib import Path
66

7+
from codeflash.code_utils.code_utils import ImportErrorPattern
78
from codeflash.models.models import TestFile, TestFiles, TestType
89
from codeflash.verification.parse_test_output import parse_test_xml
910
from codeflash.verification.test_runner import run_behavioral_tests
@@ -143,6 +144,6 @@ def test_sort():
143144
results = parse_test_xml(
144145
test_xml_file_path=result_file, test_files=test_files, test_config=config, run_result=process
145146
)
146-
match = re.search(r"^.*ModuleNotFoundError.*$", process.stdout, re.MULTILINE).group()
147+
match = ImportErrorPattern.search(process.stdout).group()
147148
assert match=="E ModuleNotFoundError: No module named 'torch'"
148149
result_file.unlink(missing_ok=True)

0 commit comments

Comments
 (0)