| """ |
| Tests for Gradio UI components. |
| |
| These tests verify: |
| - Score formatting |
| - Result gallery creation |
| - App creation |
| """ |
|
|
| import pytest |
|
|
| try: |
| from src.ui.app import format_score, create_result_gallery |
| HAS_GRADIO = True |
| except ImportError: |
| HAS_GRADIO = False |
|
|
|
|
| @pytest.mark.skipif(not HAS_GRADIO, reason="gradio not installed") |
| class TestFormatScore: |
| """Tests for format_score function.""" |
| |
| def test_format_high_score(self): |
| """Test formatting high similarity score.""" |
| result = format_score(0.9876) |
| assert result == "0.9876" |
| |
| def test_format_low_score(self): |
| """Test formatting low similarity score.""" |
| result = format_score(0.1234) |
| assert result == "0.1234" |
| |
| def test_format_zero_score(self): |
| """Test formatting zero score.""" |
| result = format_score(0.0) |
| assert result == "0.0000" |
| |
| def test_format_one_score(self): |
| """Test formatting perfect score.""" |
| result = format_score(1.0) |
| assert result == "1.0000" |
|
|
|
|
| @pytest.mark.skipif(not HAS_GRADIO, reason="gradio not installed") |
| class TestCreateResultGallery: |
| """Tests for create_result_gallery function.""" |
| |
| def test_empty_results(self): |
| """Test gallery creation with empty results.""" |
| from src.retrieval.multimodal import ModalityResult |
| |
| results = ModalityResult( |
| indices=[], |
| scores=[], |
| modalities=[], |
| query_modality="optical" |
| ) |
| |
| gallery = create_result_gallery(results) |
| |
| assert gallery == [] |
|
|
|
|
| @pytest.mark.skipif(not HAS_GRADIO, reason="gradio not installed") |
| class TestAppCreation: |
| """Tests for app creation.""" |
| |
| def test_create_app(self): |
| """Test Gradio app can be created.""" |
| from src.ui.app import create_app |
| app = create_app() |
| assert app is not None |
|
|
|
|
| |
| if __name__ == "__main__": |
| pytest.main([__file__, "-v"]) |
|
|