|
| 1 | +"""Assertions for calculator-crash-evals testcase. |
| 2 | +
|
| 3 | +This script validates that the calculator crash evaluations work correctly by: |
| 4 | +1. Reading the evaluation output from __uipath/output.json |
| 5 | +2. Validating that all evaluations have scores equal to 0 (since the calculator crashes) |
| 6 | +""" |
| 7 | + |
| 8 | +import json |
| 9 | +import os |
| 10 | + |
| 11 | + |
| 12 | +def main() -> None: |
| 13 | + """Main assertion logic.""" |
| 14 | + # Check if output file exists |
| 15 | + output_file = "__uipath/output.json" |
| 16 | + |
| 17 | + assert os.path.isfile(output_file), ( |
| 18 | + f"Evaluation output file '{output_file}' not found" |
| 19 | + ) |
| 20 | + print(f"✓ Found evaluation output file: {output_file}") |
| 21 | + |
| 22 | + # Load evaluation results |
| 23 | + with open(output_file, "r", encoding="utf-8") as f: |
| 24 | + output_data = json.load(f) |
| 25 | + |
| 26 | + print("✓ Loaded evaluation output") |
| 27 | + |
| 28 | + # Check status |
| 29 | + status = output_data.get("status") |
| 30 | + assert status == "successful", f"Evaluation run failed with status: {status}" |
| 31 | + print("✓ Evaluation run status: successful") |
| 32 | + |
| 33 | + # Extract output data |
| 34 | + output = output_data.get("output", {}) |
| 35 | + |
| 36 | + # Validate structure |
| 37 | + assert "evaluationSetResults" in output, "Missing 'evaluationSetResults' in output" |
| 38 | + |
| 39 | + evaluation_results = output["evaluationSetResults"] |
| 40 | + assert len(evaluation_results) > 0, "No evaluation results found" |
| 41 | + |
| 42 | + print(f"✓ Found {len(evaluation_results)} evaluation result(s)") |
| 43 | + |
| 44 | + # Validate each evaluation result |
| 45 | + passed_count = 0 |
| 46 | + failed_count = 0 |
| 47 | + skipped_count = 0 |
| 48 | + all_scores_zero = True |
| 49 | + |
| 50 | + for eval_result in evaluation_results: |
| 51 | + eval_name = eval_result.get("evaluationName", "Unknown") |
| 52 | + print(f"\n→ Validating: {eval_name}") |
| 53 | + |
| 54 | + try: |
| 55 | + # Validate evaluation results are present |
| 56 | + eval_run_results = eval_result.get("evaluationRunResults", []) |
| 57 | + if len(eval_run_results) == 0: |
| 58 | + print(f" ⊘ Skipping '{eval_name}' (no evaluation run results)") |
| 59 | + skipped_count += 1 |
| 60 | + continue |
| 61 | + |
| 62 | + # Check that all evaluations have scores equal to 0 |
| 63 | + all_passed = True |
| 64 | + for eval_run in eval_run_results: |
| 65 | + evaluator_name = eval_run.get("evaluatorName", "Unknown") |
| 66 | + result = eval_run.get("result", {}) |
| 67 | + score = result.get("score", 0) |
| 68 | + |
| 69 | + # Check if score is equal to 0 |
| 70 | + if score == 0: |
| 71 | + print(f" ✓ {evaluator_name}: score={score:.1f} (expected 0)") |
| 72 | + else: |
| 73 | + print(f" ✗ {evaluator_name}: score={score:.1f} (expected 0)") |
| 74 | + all_passed = False |
| 75 | + all_scores_zero = False |
| 76 | + |
| 77 | + if all_passed: |
| 78 | + print(f" ✓ All evaluators passed for '{eval_name}' (all scores are 0)") |
| 79 | + passed_count += 1 |
| 80 | + else: |
| 81 | + print(f" ✗ Some evaluators failed for '{eval_name}'") |
| 82 | + failed_count += 1 |
| 83 | + |
| 84 | + except Exception as e: |
| 85 | + print(f" ✗ Error validating '{eval_name}': {e}") |
| 86 | + failed_count += 1 |
| 87 | + |
| 88 | + # Final summary |
| 89 | + print(f"\n{'=' * 60}") |
| 90 | + print("Summary:") |
| 91 | + print(f" Total evaluations: {passed_count + failed_count + skipped_count}") |
| 92 | + print(f" ✓ Passed: {passed_count}") |
| 93 | + print(f" ✗ Failed: {failed_count}") |
| 94 | + print(f" ⊘ Skipped: {skipped_count}") |
| 95 | + print(f"{'=' * 60}") |
| 96 | + |
| 97 | + assert failed_count == 0, "Some assertions failed" |
| 98 | + assert all_scores_zero, "Not all evaluation scores are 0 as expected" |
| 99 | + |
| 100 | + print( |
| 101 | + "\n✅ All assertions passed! All scores are 0 as expected for crash scenarios." |
| 102 | + ) |
| 103 | + |
| 104 | + |
| 105 | +if __name__ == "__main__": |
| 106 | + main() |
0 commit comments