Skip to content

Commit b59882e

Browse files
committed
prevent pytest fail with non unicode chars
1 parent 6fc2c17 commit b59882e

7 files changed

Lines changed: 16 additions & 20 deletions

File tree

codeflash/code_utils/shell_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ def get_cross_platform_subprocess_run_args(
247247
capture_output: bool = True,
248248
) -> dict[str, str]:
249249
run_args = {"cwd": cwd, "env": env, "text": text, "timeout": timeout, "check": check}
250+
# When text=True, use errors='replace' to handle non-UTF-8 bytes gracefully
251+
# instead of raising UnicodeDecodeError
252+
if text:
253+
run_args["errors"] = "replace"
250254
if sys.platform == "win32":
251255
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
252256
run_args["creationflags"] = creationflags

codeflash/languages/javascript/find_references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def find_references(
213213
trigger_check = True
214214
if import_info:
215215
context.visited_files.add(file_path)
216-
import_name, original_import = import_info
216+
import_name, original_import = import_info # noqa: RUF059
217217
file_refs = self._find_references_in_file(
218218
file_path, file_code, reexport_name, import_name, file_analyzer, include_self=True
219219
)
@@ -404,7 +404,7 @@ def _find_identifier_references(
404404
name_node = node.child_by_field_name("name")
405405
if name_node:
406406
new_current_function = source_bytes[name_node.start_byte : name_node.end_byte].decode("utf8")
407-
elif node.type in ("variable_declarator",):
407+
elif node.type in ("variable_declarator",): # noqa: FURB171
408408
# Arrow function or function expression assigned to variable
409409
name_node = node.child_by_field_name("name")
410410
value_node = node.child_by_field_name("value")

codeflash/languages/javascript/parse.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
from junitparser.xunit2 import JUnitXml
1717

1818
from codeflash.cli_cmds.console import logger
19-
from codeflash.models.models import (
20-
FunctionTestInvocation,
21-
InvocationId,
22-
TestResults,
23-
TestType,
24-
)
19+
from codeflash.models.models import FunctionTestInvocation, InvocationId, TestResults, TestType
2520

2621
if TYPE_CHECKING:
2722
import subprocess

codeflash/languages/javascript/vitest_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ def run_vitest_behavioral_tests(
288288
logger.debug(f"Vitest JUnit XML created: {result_file_path} ({file_size} bytes)")
289289
if file_size < 200: # Suspiciously small - likely empty or just headers
290290
logger.warning(
291-
f"Vitest JUnit XML is very small ({file_size} bytes). "
292-
f"Content: {result_file_path.read_text()[:500]}"
291+
f"Vitest JUnit XML is very small ({file_size} bytes). Content: {result_file_path.read_text()[:500]}"
293292
)
294293
else:
295294
logger.warning(

codeflash/languages/treesitter_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,9 @@ def get_analyzer_for_file(file_path: Path) -> TreeSitterAnalyzer:
15801580
"""
15811581
suffix = file_path.suffix.lower()
15821582

1583-
if suffix in (".ts",):
1583+
if suffix in (".ts",): # noqa: FURB171
15841584
return TreeSitterAnalyzer(TreeSitterLanguage.TYPESCRIPT)
1585-
if suffix in (".tsx",):
1585+
if suffix in (".tsx",): # noqa: FURB171
15861586
return TreeSitterAnalyzer(TreeSitterLanguage.TSX)
15871587
# Default to JavaScript for .js, .jsx, .mjs, .cjs
15881588
return TreeSitterAnalyzer(TreeSitterLanguage.JAVASCRIPT)

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def _handle_empty_queue(self) -> CandidateNode | None:
315315
self.future_all_code_repair,
316316
"Repairing {0} candidates",
317317
"Added {0} candidates from repair, total candidates now: {1}",
318-
lambda: self.future_all_code_repair.clear(),
318+
lambda: self.future_all_code_repair.clear(), # noqa: PLW0108
319319
)
320320
if self.line_profiler_done and not self.refinement_done:
321321
return self._process_candidates(
@@ -330,7 +330,7 @@ def _handle_empty_queue(self) -> CandidateNode | None:
330330
self.future_adaptive_optimizations,
331331
"Applying adaptive optimizations to {0} candidates",
332332
"Added {0} candidates from adaptive optimization, total candidates now: {1}",
333-
lambda: self.future_adaptive_optimizations.clear(),
333+
lambda: self.future_adaptive_optimizations.clear(), # noqa: PLW0108
334334
)
335335
return None # All done
336336

@@ -2093,7 +2093,7 @@ def process_review(
20932093
formatted_generated_test = format_generated_code(concolic_test_str, self.args.formatter_cmds)
20942094
generated_tests_str += f"```{code_lang}\n{formatted_generated_test}\n```\n\n"
20952095

2096-
existing_tests, replay_tests, concolic_tests = existing_tests_source_for(
2096+
existing_tests, replay_tests, concolic_tests = existing_tests_source_for( # noqa: RUF059
20972097
self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root),
20982098
function_to_all_tests,
20992099
test_cfg=self.test_cfg,

codeflash/verification/parse_test_output.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import contextlib
43
import os
54
import re
65
import sqlite3
@@ -22,6 +21,9 @@
2221
)
2322
from codeflash.discovery.discover_unit_tests import discover_parameters_unittest
2423
from codeflash.languages import is_javascript
24+
25+
# Import Jest-specific parsing from the JavaScript language module
26+
from codeflash.languages.javascript.parse import parse_jest_test_xml as _parse_jest_test_xml
2527
from codeflash.models.models import (
2628
ConcurrencyMetrics,
2729
FunctionTestInvocation,
@@ -32,10 +34,6 @@
3234
)
3335
from codeflash.verification.coverage_utils import CoverageUtils, JestCoverageUtils
3436

35-
# Import Jest-specific parsing from the JavaScript language module
36-
from codeflash.languages.javascript.parse import jest_end_pattern, jest_start_pattern
37-
from codeflash.languages.javascript.parse import parse_jest_test_xml as _parse_jest_test_xml
38-
3937
if TYPE_CHECKING:
4038
import subprocess
4139

0 commit comments

Comments
 (0)