Download tests/test_detector.py from SahilCodevally/codevally-vision-language-action: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/SahilCodevally/codevally-vision-language-action/resolve/main/tests/test_detector.py
- Command line
-
hf download hf://spaces/SahilCodevally/codevally-vision-language-action/tests/test_detector.py
-
curl -L -o test_detector.py https://huggingface.co/spaces/SahilCodevally/codevally-vision-language-action/resolve/main/tests/test_detector.py
2.13 kB
| """ | |
| Tests for the Vision Module — ObjectDetector. | |
| """ | |
| import numpy as np | |
| import pytest | |
| class TestObjectDetector: | |
| """Tests for ObjectDetector.detect() method.""" | |
| def test_detect_returns_list(self): | |
| """Detection should return a list.""" | |
| from src.vision.detector import ObjectDetector | |
| detector = ObjectDetector(model_name="yolov8n.pt", confidence=0.25) | |
| # Create a synthetic test image (solid blue, 480x640) | |
| image = np.zeros((480, 640, 3), dtype=np.uint8) | |
| image[:, :] = (200, 100, 50) | |
| result = detector.detect(image) | |
| assert isinstance(result, list), "detect() must return a list" | |
| def test_detect_result_schema(self): | |
| """Each detection should have label, confidence, and bbox keys.""" | |
| from src.vision.detector import ObjectDetector | |
| detector = ObjectDetector(model_name="yolov8n.pt", confidence=0.25) | |
| # Use a real-ish image to maybe get detections | |
| image = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8) | |
| result = detector.detect(image) | |
| for det in result: | |
| assert "label" in det, "Detection must have 'label'" | |
| assert "confidence" in det, "Detection must have 'confidence'" | |
| assert "bbox" in det, "Detection must have 'bbox'" | |
| assert isinstance(det["label"], str) | |
| assert isinstance(det["confidence"], float) | |
| assert isinstance(det["bbox"], list) | |
| assert len(det["bbox"]) == 4 | |
| def test_detect_invalid_image_raises(self): | |
| """Passing None should raise ValueError.""" | |
| from src.vision.detector import ObjectDetector | |
| detector = ObjectDetector(model_name="yolov8n.pt", confidence=0.25) | |
| with pytest.raises(ValueError): | |
| detector.detect(None) | |
| def test_detect_1d_image_raises(self): | |
| """Passing a 1D array should raise ValueError.""" | |
| from src.vision.detector import ObjectDetector | |
| detector = ObjectDetector(model_name="yolov8n.pt", confidence=0.25) | |
| with pytest.raises(ValueError): | |
| detector.detect(np.array([1, 2, 3])) | |