"""站点自己挂在页面上的标识资产:header 的 `` 与页面上的 X 账号。 样本按 bambi.ne.jp 2026-09-05 的实测结构写:只声明一枚 16×16 的 `favicon.ico`, header 里挂着 `images/_/header_logo.png`,页脚一排社媒里有两个 X 账号。 """ from __future__ import annotations import unittest from peach import site_logos PAGE = """
Bambi Promotion
""" class LogoImageTests(unittest.TestCase): def test_a_shared_page_requires_the_named_owner_on_each_mark(self): html = ('Network' '別メーカー/妄想族' 'ボニータ/妄想族') self.assertEqual(site_logos.logo_images(html, 'https://network.example/maker/456/', owner='ボニータ/妄想族'), ['https://network.example/logo-own.png']) def test_an_unnamed_shared_page_mark_has_no_owner_evidence(self): self.assertEqual(site_logos.logo_images('', 'https://network.example/maker/456/', owner='ボニータ/妄想族'), []) def test_the_header_mark_is_found_and_made_absolute(self): self.assertEqual(site_logos.logo_images(PAGE, "https://bambi.ne.jp/"), ["https://bambi.ne.jp/images/_/header_logo.png"]) def test_the_hero_photograph_is_not_a_mark(self): """首屏那张大图没有任何一处说自己是标识。按位置猜「第一张图」会取到模特照。""" self.assertNotIn("https://bambi.ne.jp/images/1/image.jpg", site_logos.logo_images(PAGE, "https://bambi.ne.jp/")) def test_a_social_button_is_not_a_mark(self): """`images/_/icon/x.png` 的路径里带 x,取回来是 X 自己的鸟,不是这家公司的标识。""" self.assertEqual(site_logos.logo_images( '', "https://bambi.ne.jp/"), []) def test_the_class_and_the_alt_also_declare_a_mark(self): html = ('' 'Company logo' '') self.assertEqual(site_logos.logo_images(html, "https://x.jp/"), ["https://x.jp/assets/a1.png", "https://x.jp/assets/a2.png", "https://x.jp/assets/a3.png"]) def test_the_same_mark_twice_is_one_candidate(self): html = '' self.assertEqual(site_logos.logo_images(html, "https://x.jp/"), ["https://x.jp/logo.png"]) def test_a_lazy_loaded_mark_still_counts(self): html = '' self.assertEqual(site_logos.logo_images(html, "https://x.jp/"), ["https://x.jp/logo.png"]) def test_an_inline_placeholder_is_not_a_candidate(self): """懒加载占位图顶着标识那张 `` 的 class,词形闸门拦不住它。 取字节那一步打不开 `data:`,白等两轮重试再记一次「取不回来」;eltra.jp 2026-09-05 那一页就有两张。 """ html = ('' '') self.assertEqual(site_logos.logo_images(html, "https://x.jp/"), ["https://x.jp/logo.png"]) def test_an_empty_page_yields_nothing(self): self.assertEqual(site_logos.logo_images("", "https://x.jp/"), []) class ProfileTests(unittest.TestCase): def test_both_accounts_are_found_in_page_order(self): self.assertEqual(site_logos.x_profiles(PAGE, "https://bambi.ne.jp/"), ["https://x.com/BambiPromotion", "https://x.com/Bambi__MG"]) def test_a_share_button_is_not_an_account(self): """`x.com/intent/tweet` 的 og:image 是 X 自己的卡片图,每家取回来都一样。""" self.assertFalse(site_logos.is_x_profile("https://x.com/intent/tweet?url=a")) self.assertFalse(site_logos.is_x_profile("https://x.com/hashtag/av")) self.assertFalse(site_logos.is_x_profile("https://x.com/")) self.assertFalse(site_logos.is_x_profile("https://instagram.com/bambi")) def test_a_status_link_is_not_an_account_page(self): self.assertFalse(site_logos.is_x_profile("https://x.com/BambiPromotion/status/1")) def test_the_old_host_is_the_same_account(self): self.assertTrue(site_logos.is_x_profile("https://twitter.com/BambiPromotion")) self.assertEqual(site_logos.x_profiles( '', "https://x.jp/"), ["https://x.com/A"]) class AvatarTests(unittest.TestCase): def test_the_profile_image_falls_back_through_the_tiers(self): html = ('') tiers = site_logos.avatar_tiers(html) self.assertEqual(tiers[0], "https://pbs.twimg.com/profile_images/1/7N42mRCO.jpg") self.assertIn("_400x400", tiers[1]) def test_a_banner_is_not_an_avatar(self): """登出页有时把横幅放进 og:image。那不是头像,退回空手比装错强。""" html = ('') self.assertEqual(site_logos.avatar_tiers(html), []) def test_a_page_without_the_tag_yields_nothing(self): """Instagram 登出页就是这样:`og:image` 一条都没有(2026-09-05 实测)。""" self.assertEqual(site_logos.avatar_tiers(""), []) if __name__ == "__main__": unittest.main()