"""Tests for MarkdownConverter in kb_zhihu_metadata
Tests cover:
- Normal image conversion
- Zhihu lazy loading image handling (data-actualsrc)
- Alternative lazy loading (data-original)
- Mixed content with images
"""
import pytest
import sys
from pathlib import Path
# Add kb_zhihu_metadata to path
zhihu_metadata_path = Path(__file__).parent.parent.parent / "kb-zhihu-metadata"
if str(zhihu_metadata_path) not in sys.path:
sys.path.insert(0, str(zhihu_metadata_path))
from markdown_converter import MarkdownConverter
class TestMarkdownConverterImages:
"""Tests for image handling in MarkdownConverter"""
def test_normal_image_conversion(self):
"""Test that normal images are converted correctly"""
html = '
'
converter = MarkdownConverter()
result = converter.convert(html)
assert "" in result
def test_zhihu_lazy_load_image_with_data_actualsrc(self):
"""Test that Zhihu lazy loading images use data-actualsrc"""
html = '''


'
converter = MarkdownConverter()
result = converter.convert(html)
assert "https://example.com/normal.jpg" in result
def test_mixed_content_with_images(self):
"""Test conversion of mixed content with text and images"""
html = '''
First paragraph.
Second paragraph.
'
converter = MarkdownConverter()
result = converter.convert(html)
# Empty src is not a data: URI, so it should stay as is
assert "https://example.com/fallback.jpg" not in result
class TestMarkdownConverterBasicConversion:
"""Tests for basic HTML to Markdown conversion"""
def test_paragraphs(self):
"""Test paragraph conversion"""
html = "First
Second
" converter = MarkdownConverter() result = converter.convert(html) assert "First" in result assert "Second" in result def test_headings(self): """Test heading conversion""" html = "def hello():\n print('hello')"
converter = MarkdownConverter()
result = converter.convert(html)
assert "```" in result or "def hello():" in result