Generate a complete test file for a list of functions.
(self, functions: List[FunctionInfo], output_path: Path)
| 596 | return fixtures |
| 597 | |
| 598 | def generate_test_file(self, functions: List[FunctionInfo], output_path: Path): |
| 599 | """Generate a complete test file for a list of functions.""" |
| 600 | if not functions: |
| 601 | return |
| 602 | |
| 603 | # Group functions by file |
| 604 | files_to_test = {} |
| 605 | for func in functions: |
| 606 | file_key = func.file_path |
| 607 | if file_key not in files_to_test: |
| 608 | files_to_test[file_key] = [] |
| 609 | files_to_test[file_key].append(func) |
| 610 | |
| 611 | for file_path, file_functions in files_to_test.items(): |
| 612 | # Determine output file name |
| 613 | module_name = Path(file_path).stem |
| 614 | test_file_name = f"test_{module_name}_generated.py" |
| 615 | test_file_path = output_path / test_file_name |
| 616 | |
| 617 | # Generate test content |
| 618 | content_lines = [] |
| 619 | |
| 620 | # Header comment |
| 621 | content_lines.extend([ |
| 622 | '"""', |
| 623 | f'Generated tests for {file_path}', |
| 624 | '', |
| 625 | 'This file was automatically generated by test_generator.py', |
| 626 | 'based on coverage analysis and existing test patterns.', |
| 627 | '', |
| 628 | 'TODO items require manual implementation.', |
| 629 | '"""', |
| 630 | '' |
| 631 | ]) |
| 632 | |
| 633 | # Generate imports (use first function's imports as base) |
| 634 | if file_functions: |
| 635 | template = self.generate_test_for_function(file_functions[0]) |
| 636 | content_lines.extend(template.imports) |
| 637 | content_lines.append('') |
| 638 | |
| 639 | # Generate test class |
| 640 | class_name = f'Test{module_name.title()}Generated' |
| 641 | content_lines.extend([ |
| 642 | f'class {class_name}(unittest.TestCase):', |
| 643 | f' """Generated tests for {module_name} module."""', |
| 644 | '' |
| 645 | ]) |
| 646 | |
| 647 | # Generate fixtures (use first function's category) |
| 648 | if file_functions: |
| 649 | template = self.generate_test_for_function(file_functions[0]) |
| 650 | for fixture_line in template.fixtures: |
| 651 | content_lines.append(f' {fixture_line}') |
| 652 | content_lines.append('') |
| 653 | |
| 654 | # Generate test methods |
| 655 | for func in file_functions: |
no test coverage detected