Run standardized tests for a provider.
| 65 | # ── Test runner ─────────────────────────────────────────────────────────────── |
| 66 | |
| 67 | class TestRunner: |
| 68 | """Run standardized tests for a provider.""" |
| 69 | |
| 70 | def __init__(self, provider_name: str, config, delay_between_tests: float = 1.0): |
| 71 | self.provider_name = provider_name |
| 72 | self.executor = Executor(config) |
| 73 | self.delay = delay_between_tests |
| 74 | self.passed = 0 |
| 75 | self.failed = 0 |
| 76 | self.errors = [] |
| 77 | |
| 78 | def run_test(self, test_name, test_func): |
| 79 | """Run a single test with standard formatting.""" |
| 80 | print(f"\n{'=' * 60}") |
| 81 | print(f"TEST: {test_name}") |
| 82 | print(f"{'=' * 60}") |
| 83 | try: |
| 84 | test_func() |
| 85 | self.passed += 1 |
| 86 | print(f"\n✅ PASSED: {test_name}") |
| 87 | except Exception as e: |
| 88 | self.failed += 1 |
| 89 | error_msg = str(e) |
| 90 | self.errors.append((test_name, error_msg)) |
| 91 | print(f"\n❌ FAILED: {test_name}") |
| 92 | print(f" Error: {error_msg}") |
| 93 | traceback.print_exc() |
| 94 | if self.delay > 0: |
| 95 | time.sleep(self.delay) |
| 96 | |
| 97 | def print_summary(self): |
| 98 | """Print final test summary.""" |
| 99 | total = self.passed + self.failed |
| 100 | print(f"\n{'=' * 60}") |
| 101 | status = "ALL PASSED ✅" if self.failed == 0 else f"{self.failed} FAILED ❌" |
| 102 | print(f"[{self.provider_name}] {self.passed}/{total} {status}") |
| 103 | if self.errors: |
| 104 | print(f"\nFailed tests:") |
| 105 | for name, err in self.errors: |
| 106 | print(f" ❌ {name}: {err[:100]}") |
| 107 | print(f"{'=' * 60}") |
| 108 | return self.failed == 0 |
| 109 | |
| 110 | # ── Standard test cases ─────────────────────────────────────────────── |
| 111 | |
| 112 | def test_single_tool_call(self): |
| 113 | """Test 1: Single tool call (add 5 + 3 = 8).""" |
| 114 | def run(): |
| 115 | workflow = Workflow(f"{self.provider_name}Single") |
| 116 | agent = Node.agent( |
| 117 | name="Calc", |
| 118 | prompt="Calculate 5 + 3 STRICTLY using the available add tool. Return ONLY the numeric result.", |
| 119 | tools=[add], |
| 120 | ) |
| 121 | workflow.add_node(agent) |
| 122 | result = self.executor.execute(workflow) |
| 123 | output = result.get_node_output("Calc") |
| 124 | metadata = result.get_node_response_metadata("Calc") |
no outgoing calls
no test coverage detected