| 720 | ] |
| 721 | |
| 722 | def run_tests(schema, test_cases): |
| 723 | print("Starting test cases...\n") |
| 724 | for idx, test in enumerate(test_cases, 1): |
| 725 | data = test["data"] |
| 726 | expected = test["expected"] |
| 727 | name = test["name"] |
| 728 | try: |
| 729 | validate(instance=data, schema=schema) |
| 730 | result = True |
| 731 | error_message = "" |
| 732 | except ValidationError as e: |
| 733 | result = False |
| 734 | error_message = e.message |
| 735 | |
| 736 | status = "PASS" if result == expected else "FAIL" |
| 737 | print(f"Test Case {idx}: {name}") |
| 738 | print(f" Expected Result: {'Valid' if expected else 'Invalid'}") |
| 739 | print(f" Actual Result: {'Valid' if result else 'Invalid'}") |
| 740 | if status == "FAIL": |
| 741 | print(f" Error Message: {error_message}") |
| 742 | print(f" Test Status: {status}\n") |
| 743 | |
| 744 | print("Testing completed.") |
| 745 | |
| 746 | |
| 747 | if __name__ == "__main__": |