|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from mcp.server.mcpserver import Audio, Image |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + ("format_val", "expected_mime"), |
| 10 | + [ |
| 11 | + ("jpg", "image/jpeg"), |
| 12 | + ("jpeg", "image/jpeg"), |
| 13 | + ("png", "image/png"), |
| 14 | + ("gif", "image/gif"), |
| 15 | + ("webp", "image/webp"), |
| 16 | + ("bmp", "image/bmp"), |
| 17 | + (".jpg", "image/jpeg"), |
| 18 | + ("JPG", "image/jpeg"), |
| 19 | + ], |
| 20 | +) |
| 21 | +def test_image_format_mime_types(format_val: str, expected_mime: str) -> None: |
| 22 | + img = Image(data=b"\x00", format=format_val) |
| 23 | + assert img.to_image_content().mime_type == expected_mime |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.parametrize( |
| 27 | + ("filename", "expected_mime"), |
| 28 | + [ |
| 29 | + ("chart.jpg", "image/jpeg"), |
| 30 | + ("chart.jpeg", "image/jpeg"), |
| 31 | + ("chart.png", "image/png"), |
| 32 | + ("chart.gif", "image/gif"), |
| 33 | + ("chart.webp", "image/webp"), |
| 34 | + ("chart.unknown", "application/octet-stream"), |
| 35 | + ], |
| 36 | +) |
| 37 | +def test_image_path_mime_types(filename: str, expected_mime: str, tmp_path: Path) -> None: |
| 38 | + file_path = tmp_path / filename |
| 39 | + file_path.write_bytes(b"\x00") |
| 40 | + img = Image(path=file_path) |
| 41 | + assert img.to_image_content().mime_type == expected_mime |
| 42 | + |
| 43 | + |
| 44 | +def test_image_raw_data_default_mime_type() -> None: |
| 45 | + img = Image(data=b"\x00") |
| 46 | + assert img.to_image_content().mime_type == "image/png" |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.parametrize( |
| 50 | + ("format_val", "expected_mime"), |
| 51 | + [ |
| 52 | + ("mp3", "audio/mpeg"), |
| 53 | + ("m4a", "audio/mp4"), |
| 54 | + ("wav", "audio/wav"), |
| 55 | + ("ogg", "audio/ogg"), |
| 56 | + ("flac", "audio/flac"), |
| 57 | + ("aac", "audio/aac"), |
| 58 | + ("opus", "audio/opus"), |
| 59 | + (".mp3", "audio/mpeg"), |
| 60 | + ("MP3", "audio/mpeg"), |
| 61 | + ], |
| 62 | +) |
| 63 | +def test_audio_format_mime_types(format_val: str, expected_mime: str) -> None: |
| 64 | + audio = Audio(data=b"\x00", format=format_val) |
| 65 | + assert audio.to_audio_content().mime_type == expected_mime |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.parametrize( |
| 69 | + ("filename", "expected_mime"), |
| 70 | + [ |
| 71 | + ("chime.mp3", "audio/mpeg"), |
| 72 | + ("chime.m4a", "audio/mp4"), |
| 73 | + ("chime.wav", "audio/wav"), |
| 74 | + ("chime.ogg", "audio/ogg"), |
| 75 | + ("chime.flac", "audio/flac"), |
| 76 | + ("chime.aac", "audio/aac"), |
| 77 | + ("chime.unknown", "application/octet-stream"), |
| 78 | + ], |
| 79 | +) |
| 80 | +def test_audio_path_mime_types(filename: str, expected_mime: str, tmp_path: Path) -> None: |
| 81 | + file_path = tmp_path / filename |
| 82 | + file_path.write_bytes(b"\x00") |
| 83 | + audio = Audio(path=file_path) |
| 84 | + assert audio.to_audio_content().mime_type == expected_mime |
| 85 | + |
| 86 | + |
| 87 | +def test_audio_raw_data_default_mime_type() -> None: |
| 88 | + audio = Audio(data=b"\x00") |
| 89 | + assert audio.to_audio_content().mime_type == "audio/wav" |
0 commit comments