Spaces:
Sleeping
Sleeping
Download test_ai_engine.py from DhyandevP/entri-proctor-api: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/DhyandevP/entri-proctor-api/resolve/main/test_ai_engine.py
- Command line
-
hf download hf://spaces/DhyandevP/entri-proctor-api/test_ai_engine.py
-
curl -L -o test_ai_engine.py https://huggingface.co/spaces/DhyandevP/entri-proctor-api/resolve/main/test_ai_engine.py
1.35 kB
| import os | |
| import sys | |
| import unittest | |
| import cv2 | |
| import numpy as np | |
| # Ensure midend_api path is importable | |
| sys.path.insert(0, os.path.dirname(__file__)) | |
| from ai_engine import AIEngine | |
| class TestAIEngine(unittest.TestCase): | |
| def setUpClass(cls): | |
| cls.engine = AIEngine() | |
| def _encode_frame(self, frame: np.ndarray) -> bytes: | |
| ok, buf = cv2.imencode(".jpg", frame) | |
| self.assertTrue(ok, "Failed to encode test frame") | |
| return buf.tobytes() | |
| def test_engine_init(self): | |
| self.assertIsNotNone(self.engine.face_detector) | |
| def test_blank_image(self): | |
| # Plain black background - should report no face | |
| blank = np.zeros((320, 320, 3), dtype=np.uint8) | |
| result = self.engine.analyze(self._encode_frame(blank)) | |
| self.assertFalse(result["face_detected"]) | |
| self.assertFalse(result["multiple_faces_detected"]) | |
| self.assertFalse(result["partial_face_detected"]) | |
| self.assertFalse(result["forbidden_objects"]) | |
| def test_invalid_inputs(self): | |
| # Empty byte stream | |
| with self.assertRaises(ValueError): | |
| self.engine.analyze(b"") | |
| # Corrupted non-image bytes | |
| with self.assertRaises(ValueError): | |
| self.engine.analyze(b"not_an_image_buffer") | |
| if __name__ == "__main__": | |
| unittest.main() | |