Run a test with the given request data.
(test_name, request_data, check_tools=False)
| 316 | return True # We're not enforcing similarity, just basic structure |
| 317 | |
| 318 | def test_request(test_name, request_data, check_tools=False): |
| 319 | """Run a test with the given request data.""" |
| 320 | print(f"\n{'='*20} RUNNING TEST: {test_name} {'='*20}") |
| 321 | |
| 322 | # Log the request data |
| 323 | print(f"\nRequest data:\n{json.dumps({k: v for k, v in request_data.items() if k != 'messages'}, indent=2)}") |
| 324 | |
| 325 | # Make copies of the request data to avoid modifying the original |
| 326 | anthropic_data = request_data.copy() |
| 327 | proxy_data = request_data.copy() |
| 328 | |
| 329 | try: |
| 330 | # Send requests to both APIs |
| 331 | print("\nSending to Anthropic API...") |
| 332 | anthropic_response = get_response(ANTHROPIC_API_URL, anthropic_headers, anthropic_data) |
| 333 | |
| 334 | print("\nSending to Proxy...") |
| 335 | proxy_response = get_response(PROXY_API_URL, proxy_headers, proxy_data) |
| 336 | |
| 337 | # Check response codes |
| 338 | print(f"\nAnthropic status code: {anthropic_response.status_code}") |
| 339 | print(f"Proxy status code: {proxy_response.status_code}") |
| 340 | |
| 341 | if anthropic_response.status_code != 200 or proxy_response.status_code != 200: |
| 342 | print("\n⚠️ One or both requests failed") |
| 343 | if anthropic_response.status_code != 200: |
| 344 | print(f"Anthropic error: {anthropic_response.text}") |
| 345 | if proxy_response.status_code != 200: |
| 346 | print(f"Proxy error: {proxy_response.text}") |
| 347 | return False |
| 348 | |
| 349 | # Compare the responses |
| 350 | result = compare_responses(anthropic_response, proxy_response, check_tools=check_tools) |
| 351 | if result: |
| 352 | print(f"\n✅ Test {test_name} passed!") |
| 353 | return True |
| 354 | else: |
| 355 | print(f"\n❌ Test {test_name} failed!") |
| 356 | return False |
| 357 | |
| 358 | except Exception as e: |
| 359 | print(f"\n❌ Error in test {test_name}: {str(e)}") |
| 360 | import traceback |
| 361 | traceback.print_exc() |
| 362 | return False |
| 363 | |
| 364 | # ================= STREAMING TESTS ================= |
| 365 |
no test coverage detected