Download tests/test_visualizer.py from SahilCodevally/codevally-vision-language-action: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/spaces/SahilCodevally/codevally-vision-language-action/resolve/e1c010e5116a062fd970a76c8eaa3dddbf5c4d4b/tests/test_visualizer.py
- Command line
-
hf download hf://spaces/SahilCodevally/codevally-vision-language-action@e1c010e5116a062fd970a76c8eaa3dddbf5c4d4b/tests/test_visualizer.py
-
curl -L -o test_visualizer.py https://huggingface.co/spaces/SahilCodevally/codevally-vision-language-action/resolve/e1c010e5116a062fd970a76c8eaa3dddbf5c4d4b/tests/test_visualizer.py
3.61 kB
| """ | |
| Tests for the Visualization Module — ActionVisualizer. | |
| """ | |
| import numpy as np | |
| import pytest | |
| from src.visualization.visualizer import ActionVisualizer | |
| class TestActionVisualizer: | |
| """Tests for ActionVisualizer methods.""" | |
| def visualizer(self) -> ActionVisualizer: | |
| return ActionVisualizer() | |
| def test_image(self) -> np.ndarray: | |
| """A 480x640 synthetic test image.""" | |
| return np.zeros((480, 640, 3), dtype=np.uint8) | |
| def sample_detections(self) -> list[dict]: | |
| return [ | |
| {"label": "bottle", "confidence": 0.92, "bbox": [100, 150, 200, 350]}, | |
| {"label": "box", "confidence": 0.85, "bbox": [400, 300, 550, 500]}, | |
| ] | |
| def sample_action_plan(self) -> dict: | |
| return { | |
| "action": "move", | |
| "steps": [ | |
| "Step 1: Locate 'bottle'", | |
| "Step 2: Locate 'box'", | |
| "Step 3: Move 'bottle' → 'box'", | |
| "Step 4: Verify action completion", | |
| ], | |
| "source_bbox": [100, 150, 200, 350], | |
| "dest_bbox": [400, 300, 550, 500], | |
| "status": "success", | |
| } | |
| def test_draw_detections_returns_image( | |
| self, visualizer, test_image, sample_detections | |
| ): | |
| """draw_detections should return an image of the same shape.""" | |
| result = visualizer.draw_detections(test_image, sample_detections) | |
| assert isinstance(result, np.ndarray) | |
| assert result.shape == test_image.shape | |
| def test_draw_detections_modifies_image( | |
| self, visualizer, test_image, sample_detections | |
| ): | |
| """draw_detections should modify the image (not return a blank copy).""" | |
| result = visualizer.draw_detections(test_image, sample_detections) | |
| # The annotated image should differ from the original | |
| assert not np.array_equal(result, test_image) | |
| def test_draw_detections_empty_list(self, visualizer, test_image): | |
| """draw_detections with empty list should still return an image.""" | |
| result = visualizer.draw_detections(test_image, []) | |
| assert isinstance(result, np.ndarray) | |
| assert result.shape == test_image.shape | |
| def test_visualize_returns_image( | |
| self, visualizer, test_image, sample_action_plan | |
| ): | |
| """visualize should return an image of the same shape.""" | |
| result = visualizer.visualize(test_image, sample_action_plan) | |
| assert isinstance(result, np.ndarray) | |
| assert result.shape == test_image.shape | |
| def test_visualize_modifies_image( | |
| self, visualizer, test_image, sample_action_plan | |
| ): | |
| """visualize should modify the image.""" | |
| result = visualizer.visualize(test_image, sample_action_plan) | |
| assert not np.array_equal(result, test_image) | |
| def test_visualize_with_no_bboxes(self, visualizer, test_image): | |
| """visualize should handle missing bounding boxes gracefully.""" | |
| plan = { | |
| "action": "inspect", | |
| "steps": ["Step 1: Inspect object"], | |
| "source_bbox": None, | |
| "dest_bbox": None, | |
| "status": "failed", | |
| } | |
| result = visualizer.visualize(test_image, plan) | |
| assert isinstance(result, np.ndarray) | |
| assert result.shape == test_image.shape | |
| def test_draw_detections_invalid_image(self, visualizer): | |
| """draw_detections with None should return a fallback image.""" | |
| result = visualizer.draw_detections(None, []) | |
| assert isinstance(result, np.ndarray) | |