Download test_cases.py from dthart/Build3pt2: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/dthart/Build3pt2/resolve/main/test_cases.py
- Command line
-
hf download hf://spaces/dthart/Build3pt2/test_cases.py
-
curl -L -o test_cases.py https://huggingface.co/spaces/dthart/Build3pt2/resolve/main/test_cases.py
2.67 kB
| """Automated checks for the supplied inference engine. | |
| Run locally with: python -m unittest -v test_cases.py | |
| """ | |
| import unittest | |
| from inference_engine import infer | |
| from knowledge_base import NO, UNKNOWN, YES | |
| class InferenceEngineTests(unittest.TestCase): | |
| def test_missing_authentication_uses_derived_fact(self): | |
| result = infer( | |
| { | |
| "backend_running": YES, | |
| "health_check_passed": YES, | |
| "request_reached_server": YES, | |
| "cors_error_visible": NO, | |
| "api_key_present": NO, | |
| "status_code": "401", | |
| } | |
| ) | |
| self.assertTrue(result.derived_facts["network_path_ok"]) | |
| self.assertIn("Required authentication is missing", result.diagnoses) | |
| self.assertTrue(any("R6 fired" in step for step in result.trace)) | |
| def test_cors_diagnosis(self): | |
| result = infer( | |
| { | |
| "backend_running": YES, | |
| "health_check_passed": UNKNOWN, | |
| "request_reached_server": NO, | |
| "cors_error_visible": YES, | |
| "api_key_present": UNKNOWN, | |
| "status_code": "", | |
| } | |
| ) | |
| self.assertIn("Browser request blocked by CORS policy", result.diagnoses) | |
| def test_unknown_is_not_false(self): | |
| result = infer( | |
| { | |
| "backend_running": UNKNOWN, | |
| "health_check_passed": UNKNOWN, | |
| "request_reached_server": UNKNOWN, | |
| "cors_error_visible": UNKNOWN, | |
| "api_key_present": UNKNOWN, | |
| "status_code": "", | |
| } | |
| ) | |
| self.assertEqual(result.diagnoses, []) | |
| self.assertGreaterEqual(len(result.unknown_inputs), 6) | |
| def test_conflicting_observations_are_reported(self): | |
| result = infer( | |
| { | |
| "backend_running": NO, | |
| "health_check_passed": YES, | |
| "request_reached_server": UNKNOWN, | |
| "cors_error_visible": UNKNOWN, | |
| "api_key_present": UNKNOWN, | |
| "status_code": "", | |
| } | |
| ) | |
| self.assertTrue(result.conflicts) | |
| def test_server_failure(self): | |
| result = infer( | |
| { | |
| "backend_running": YES, | |
| "health_check_passed": YES, | |
| "request_reached_server": YES, | |
| "cors_error_visible": NO, | |
| "api_key_present": YES, | |
| "status_code": "503", | |
| } | |
| ) | |
| self.assertIn("Server-side application failure", result.diagnoses) | |
| if __name__ == "__main__": | |
| unittest.main() | |