"""Unit tests for cores.search — HTTP + image extraction + UA.""" from __future__ import annotations from cores.search import extract_image_urls_from_html, is_social_media_url, random_user_agent class TestExtractImageUrls: def test_extracts_img_src(self): html = '
'
imgs = extract_image_urls_from_html(html, base_url="https://example.com/")
assert len(imgs) == 1
assert imgs[0]["url"] == "https://example.com/a.jpg"
assert imgs[0]["alt"] == "A"
def test_resolves_relative_urls(self):
html = '
'
imgs = extract_image_urls_from_html(html, base_url="https://example.com/page")
assert imgs[0]["url"] == "https://example.com/images/b.png"
def test_skips_data_uris(self):
html = '
' for i in range(100))
imgs = extract_image_urls_from_html(html, max_images=10)
assert len(imgs) == 10
def test_handles_data_src(self):
html = '
'
imgs = extract_image_urls_from_html(html, base_url="https://example.com/")
assert len(imgs) == 1
def test_malformed_html_does_not_crash(self):
html = "
'
imgs = extract_image_urls_from_html(html, base_url="https://example.com/")
assert len(imgs) == 1
assert imgs[0]["url"] == "https://example.com/lazy.jpg"
def test_dedupes_urls(self):
html = '