Display test statistics.
(results: list[RequestResult])
| 123 | |
| 124 | |
| 125 | def display_statistics(results: list[RequestResult]) -> None: |
| 126 | """Display test statistics.""" |
| 127 | successful = [r for r in results if r.success] |
| 128 | failed = [r for r in results if not r.success] |
| 129 | |
| 130 | if not successful: |
| 131 | console.print("\n✗ All requests failed", style="red") |
| 132 | return |
| 133 | |
| 134 | times = [r.response_time_ms for r in successful] |
| 135 | |
| 136 | table = Table(title="Test Statistics") |
| 137 | table.add_column("Metric", style="cyan") |
| 138 | table.add_column("Value", style="magenta") |
| 139 | |
| 140 | table.add_row("Total Requests", str(len(results))) |
| 141 | table.add_row( |
| 142 | "Successful", f"{len(successful)} ({len(successful) / len(results) * 100:.0f}%)" |
| 143 | ) |
| 144 | table.add_row("Failed", f"{len(failed)} ({len(failed) / len(results) * 100:.0f}%)") |
| 145 | table.add_row("Min Response Time", f"{min(times):.1f} ms") |
| 146 | table.add_row("Max Response Time", f"{max(times):.1f} ms") |
| 147 | table.add_row("Avg Response Time", f"{sum(times) / len(times):.1f} ms") |
| 148 | |
| 149 | console.print() |
| 150 | console.print(table) |
| 151 | |
| 152 | if len(successful) == len(results): |
| 153 | console.print("\n✓ All tests passed!", style="green bold") |
| 154 | else: |
| 155 | console.print(f"\n⚠ {len(failed)} test(s) failed", style="yellow bold") |
| 156 | |
| 157 | |
| 158 | def main() -> int: |