"""Tests für die Vision-LLM JSON-Extraktion.""" import pytest from musiksammlung.vision_llm import _extract_json def test_extract_pure_json(): text = '{"artist": "Test", "album": "Album"}' assert '"Test"' in _extract_json(text) def test_extract_json_from_markdown_block(): text = 'Hier ist das Ergebnis:\n```json\n{"artist": "Test"}\n```\nFertig.' assert '"Test"' in _extract_json(text) def test_extract_json_with_thinking_tags(): text = 'Ich denke nach...\n{"artist": "Test", "album": "X"}' result = _extract_json(text) assert '"Test"' in result def test_extract_json_with_surrounding_text(): text = 'Das JSON:\n{"artist": "A", "album": "B"}\nEnde.' result = _extract_json(text) assert '"A"' in result def test_extract_json_empty_raises(): with pytest.raises(ValueError, match="Leere Antwort"): _extract_json("") def test_extract_json_no_json_raises(): with pytest.raises(ValueError, match="Kein JSON"): _extract_json("Hier ist kein JSON, nur Text.")