We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Vasallo94/obsidian-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
test_image_indexing.py•2.79 KiB
from obsidian_mcp.semantic import indexer
class TestImageCaptionExtraction:
"""Test the extraction of captions from image links."""
def test_extract_single_image_with_caption(self):
"""Should extract a single caption from a wikilink."""
content = "Some text ![[image.png|A beautiful sunset]] more text."
captions = indexer.extract_image_captions(content)
assert len(captions) == 1
assert captions[0] == "A beautiful sunset"
def test_extract_multiple_images_with_captions(self):
"""Should extract multiple captions."""
content = """
Here is ![[img1.png|First caption]]
And another ![[img2.jpg|Second caption]]
"""
captions = indexer.extract_image_captions(content)
assert len(captions) == 2
assert "First caption" in captions
assert "Second caption" in captions
def test_ignore_images_without_captions(self):
"""Should ignore images that have no caption."""
content = "![[image.png]] and ![[other.jpg|]]"
captions = indexer.extract_image_captions(content)
assert len(captions) == 0
def test_ignore_wikilinks_that_are_not_images(self):
"""Should ignore normal wikilinks even with aliases."""
content = "[[Note|Alias]] is not an image."
captions = indexer.extract_image_captions(content)
assert len(captions) == 0
def test_mixed_content_handling(self):
"""Should handle mixed content correctly."""
content = """
# Header
![[diagram.png|A complex diagram]]
Refers to [[Concept]].
Another image ![[photo.jpg|A nice photo]] inline.
"""
captions = indexer.extract_image_captions(content)
assert "A complex diagram" in captions
assert "A nice photo" in captions
def test_standard_markdown_images(self):
"""Should extract captions from standard markdown images ."""
content = "Here is specific data: "
captions = indexer.extract_image_captions(content)
assert len(captions) == 1
assert captions[0] == "Graph of growth"
class TestDocumentEnrichment:
"""Test that documents are correctly enriched with captions."""
def test_document_includes_captions_in_content(self):
"""Document content should be appended with captions."""
# We need to mock the functions called by load_documents_from_paths
# typically this would be an integration test or use mocks
# For simplicity, we can test logic if we extracted the enrichment function
# But here we rely on the fact that we modified the function itself.
pass
def test_no_change_if_no_captions(self):
"""Document should stay same if no captions."""
pass