Collection of related test cases
| 36 | |
| 37 | |
| 38 | class TestSuite: |
| 39 | """Collection of related test cases""" |
| 40 | def __init__(self, name: str, description: str): |
| 41 | self.name = name |
| 42 | self.description = description |
| 43 | self.test_cases: List[TestCase] = [] |
| 44 | self.passed = 0 |
| 45 | self.failed = 0 |
| 46 | self.duration = 0.0 |
| 47 | |
| 48 | def add_test(self, test: TestCase): |
| 49 | """Add a test case to the suite""" |
| 50 | self.test_cases.append(test) |
| 51 | |
| 52 | def run(self, verbose: bool = False) -> bool: |
| 53 | """Run all tests in the suite""" |
| 54 | print(f"\n{BOLD}Running {self.name}{RESET}") |
| 55 | print("-" * 60) |
| 56 | |
| 57 | start_time = time.time() |
| 58 | self.passed = 0 |
| 59 | self.failed = 0 |
| 60 | |
| 61 | for test in self.test_cases: |
| 62 | test_start = time.time() |
| 63 | |
| 64 | if verbose: |
| 65 | print(f" {test.name}: ", end="", flush=True) |
| 66 | |
| 67 | try: |
| 68 | result = subprocess.run( |
| 69 | test.command, |
| 70 | shell=True, |
| 71 | capture_output=True, |
| 72 | text=True, |
| 73 | timeout=30, |
| 74 | cwd=Path(__file__).parent |
| 75 | ) |
| 76 | |
| 77 | test.output = result.stdout |
| 78 | test.error = result.stderr |
| 79 | test.passed = result.returncode == 0 |
| 80 | |
| 81 | # Check for specific error patterns that indicate failure |
| 82 | if "ERROR:" in test.output or "ERROR:" in test.error: |
| 83 | if "No files found" not in test.error: # Ignore missing file errors in test data |
| 84 | test.passed = False |
| 85 | |
| 86 | except subprocess.TimeoutExpired: |
| 87 | test.passed = False |
| 88 | test.error = "Test timed out after 30 seconds" |
| 89 | except Exception as e: |
| 90 | test.passed = False |
| 91 | test.error = str(e) |
| 92 | |
| 93 | test.duration = time.time() - test_start |
| 94 | |
| 95 | if test.passed: |
no outgoing calls