|
1 | 1 | # ruff: noqa: SLF001 |
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | | -import concurrent.futures |
5 | 4 | import hashlib |
6 | | -import multiprocessing |
7 | 5 | import os |
8 | 6 | import pickle |
9 | 7 | import re |
|
25 | 23 | from codeflash.models.models import CodePosition, FunctionCalledInTest, TestsInFile, TestType |
26 | 24 |
|
27 | 25 | if TYPE_CHECKING: |
28 | | - from multiprocessing.synchronize import Lock |
29 | | - |
30 | 26 | from codeflash.verification.verification_utils import TestConfig |
31 | 27 |
|
32 | 28 |
|
@@ -288,33 +284,23 @@ def discover_parameters_unittest(function_name: str) -> tuple[bool, str, str | N |
288 | 284 |
|
289 | 285 |
|
290 | 286 | def _process_single_test_file( |
291 | | - test_file: Path, |
292 | | - functions: list[TestsInFile], |
293 | | - project_root_path: Path, |
294 | | - test_framework: str, |
295 | | - jedi_lock: Optional[Lock] = None, |
| 287 | + test_file: Path, functions: list[TestsInFile], project_root_path: Path, test_framework: str |
296 | 288 | ) -> tuple[Path, set]: |
297 | 289 | import jedi |
298 | 290 |
|
299 | 291 | local_function_to_test_map = set() |
300 | 292 |
|
301 | 293 | try: |
302 | | - if jedi_lock is not None: |
303 | | - jedi_lock.acquire() |
304 | | - try: |
305 | | - jedi_project = jedi.Project(path=project_root_path) |
306 | | - script = jedi.Script(path=test_file, project=jedi_project) |
307 | | - test_functions = set() |
308 | | - |
309 | | - all_names = script.get_names(all_scopes=True, references=True) |
310 | | - all_defs = script.get_names(all_scopes=True, definitions=True) |
311 | | - all_names_top = script.get_names(all_scopes=True) |
312 | | - |
313 | | - top_level_functions = {name.name: name for name in all_names_top if name.type == "function"} |
314 | | - top_level_classes = {name.name: name for name in all_names_top if name.type == "class"} |
315 | | - finally: |
316 | | - if jedi_lock is not None: |
317 | | - jedi_lock.release() |
| 294 | + jedi_project = jedi.Project(path=project_root_path) |
| 295 | + script = jedi.Script(path=test_file, project=jedi_project) |
| 296 | + test_functions = set() |
| 297 | + |
| 298 | + all_names = script.get_names(all_scopes=True, references=True) |
| 299 | + all_defs = script.get_names(all_scopes=True, definitions=True) |
| 300 | + all_names_top = script.get_names(all_scopes=True) |
| 301 | + |
| 302 | + top_level_functions = {name.name: name for name in all_names_top if name.type == "function"} |
| 303 | + top_level_classes = {name.name: name for name in all_names_top if name.type == "class"} |
318 | 304 | except Exception as e: |
319 | 305 | logger.debug(f"Failed to get jedi script for {test_file}: {e}") |
320 | 306 | return test_file, local_function_to_test_map |
@@ -393,13 +379,7 @@ def _process_single_test_file( |
393 | 379 | continue |
394 | 380 |
|
395 | 381 | try: |
396 | | - if jedi_lock is not None: |
397 | | - jedi_lock.acquire() |
398 | | - try: |
399 | | - definition = name.goto(follow_imports=True, follow_builtin_imports=False) |
400 | | - finally: |
401 | | - if jedi_lock is not None: |
402 | | - jedi_lock.release() |
| 382 | + definition = name.goto(follow_imports=True, follow_builtin_imports=False) |
403 | 383 | except Exception as e: |
404 | 384 | logger.debug(str(e)) |
405 | 385 | continue |
@@ -453,25 +433,17 @@ def process_test_files( |
453 | 433 | test_framework = cfg.test_framework |
454 | 434 |
|
455 | 435 | function_to_test_map = defaultdict(set) |
456 | | - jedi_lock = multiprocessing.Manager().Lock() |
457 | | - |
458 | | - with ( |
459 | | - test_files_progress_bar(total=len(file_to_test_map), description="Processing test files") as ( |
460 | | - progress, |
461 | | - task_id, |
462 | | - ), |
463 | | - concurrent.futures.ProcessPoolExecutor() as executor, |
| 436 | + |
| 437 | + with test_files_progress_bar(total=len(file_to_test_map), description="Processing test files") as ( |
| 438 | + progress, |
| 439 | + task_id, |
464 | 440 | ): |
465 | | - futures = { |
466 | | - executor.submit( |
467 | | - _process_single_test_file, test_file, functions, project_root_path, test_framework, jedi_lock |
468 | | - ): (test_file, functions) |
469 | | - for test_file, functions in file_to_test_map.items() |
470 | | - } |
471 | | - for future in concurrent.futures.as_completed(futures): |
472 | | - _, local_results = future.result() |
| 441 | + for test_file, functions in file_to_test_map.items(): |
| 442 | + _, local_results = _process_single_test_file(test_file, functions, project_root_path, test_framework) |
| 443 | + |
473 | 444 | for qualified_name, function_called_in_test in local_results: |
474 | 445 | function_to_test_map[qualified_name].add(function_called_in_test) |
| 446 | + |
475 | 447 | progress.advance(task_id) |
476 | 448 |
|
477 | 449 | function_to_tests_dict = {function: list(tests) for function, tests in function_to_test_map.items()} |
|
0 commit comments