#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 配图简洁性与去文字化自动化测试 (TDD - Test-Driven Development) 验证要求: 1. 网站配图必须简洁高质感,绝不能是文字介绍类的图片(无冗余业务文字、功能列表、参数指标等)。 2. showcases 核心配图(服务3张、产品4张、案例4张)必须为纯粹的高端视觉图形或概念拓扑,text 标签数量严格限制(≤ 1,仅允许极简中式印章微标如单字印文或纯图形无文字)。 3. articles 封面配图必须为极简抽象科技艺术构图,杜绝长篇标题与说明文字堆砌(text 标签 ≤ 1)。 4. 严格遵循现代中式浅色专业风规范(背景 #FFFFFF / #F8FAFC,主色 #2563EB 科技蓝,辅色 #06B6D4 青 / #7C3AED 紫,细线与留白)。 5. 配图文件完整存在且大小合理,SVG 语法严格闭合。 """ import os import re import unittest BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) class ConciseShowcaseImagesTest(unittest.TestCase): def setUp(self): self.showcases_dir = os.path.join(BASE_DIR, 'public', 'assets', 'addons', 'official', 'images', 'showcases') self.articles_dir = os.path.join(BASE_DIR, 'public', 'assets', 'addons', 'official', 'images', 'articles') self.core_showcase_files = [ # 服务类 'service_middle.svg', 'service_app.svg', 'service_agent.svg', # 产品类 'product_mall.svg', 'product_pos.svg', 'product_erp.svg', 'product_saas.svg', # 案例类 'case_distrib.svg', 'case_catering.svg', 'case_gov_agent.svg', 'case_manufacture.svg' ] self.article_files = [ 'article_microservice.svg', 'article_cross_app.svg', 'article_ai_agent.svg', 'article_pos_offline.svg', 'article_erp_bom.svg', 'article_security_whitepaper.svg', 'article_southwest_digital.svg', 'article_tdd_standards.svg' ] def test_01_showcases_are_concise_not_text_intro(self): """核心业务配图必须简洁纯粹,杜绝文字介绍类图片(text 标签不超过1个,严禁包含业务功能段落)""" self.assertTrue(os.path.isdir(self.showcases_dir), "showcases 目录必须存在") text_regex = re.compile(r']*>(.*?)', re.DOTALL | re.IGNORECASE) for fname in self.core_showcase_files: fpath = os.path.join(self.showcases_dir, fname) self.assertTrue(os.path.isfile(fpath), f"配图 {fname} 必须存在") with open(fpath, 'r', encoding='utf-8') as f: content = f.read() # 提取所有 标签中实际显示的文字 matches = text_regex.findall(content) clean_texts = [re.sub(r'<[^>]+>', '', m).strip() for m in matches if m.strip()] # 简洁要求:可见文字数量 ≤ 1(纯图形无文字,或最多仅含极简单字印章如'研'/'商'/'通'等) self.assertLessEqual( len(clean_texts), 1, f"配图 {fname} 必须简洁,不能是文字介绍类图片!当前检测到 {len(clean_texts)} 处文字: {clean_texts[:5]}" ) # 严禁在可见文本中出现功能描述词、参数指标词、业务列表等 forbidden_intro_words = [ '控制台', '架构', '文档分块', '向量化', '网关', '订单', '履约', '调度', '分销', '营销', '收银', '核销', '物料', '进销存', 'SaaS', '多租户', 'API' ] all_visible_text = ' '.join(clean_texts) for word in forbidden_intro_words: self.assertNotIn(word, all_visible_text, f"配图 {fname} 中严禁出现业务介绍文字: '{word}'") def test_02_articles_are_concise_artwork(self): """文章封面必须简洁大气,不能包含大段标题或业务文字(text 标签不超过1个)""" if os.path.isdir(self.articles_dir): text_regex = re.compile(r']*>(.*?)', re.DOTALL | re.IGNORECASE) for fname in self.article_files: fpath = os.path.join(self.articles_dir, fname) if os.path.isfile(fpath): with open(fpath, 'r', encoding='utf-8') as f: content = f.read() matches = text_regex.findall(content) clean_texts = [re.sub(r'<[^>]+>', '', m).strip() for m in matches if m.strip()] self.assertLessEqual( len(clean_texts), 1, f"文章配图 {fname} 必须简洁,不能堆砌冗长介绍文字!当前有 {len(clean_texts)} 处文字: {clean_texts[:5]}" ) def test_03_color_palette_and_modern_style(self): """配图必须符合浅色专业风现代中式设计规范(含 #2563EB 科技蓝与浅色背景)""" for fname in self.core_showcase_files: fpath = os.path.join(self.showcases_dir, fname) with open(fpath, 'r', encoding='utf-8') as f: content = f.read() # 浅色系与主色 self.assertTrue( '#2563EB' in content or '#1D4ED8' in content or '#3B82F6' in content, f"配图 {fname} 必须包含主色科技蓝 (#2563EB)" ) self.assertTrue( '#FFFFFF' in content or '#F8FAFC' in content or '#EFF6FF' in content, f"配图 {fname} 必须为浅色专业风底色" ) def test_04_svg_structure_validity(self): """SVG 必须具有合法闭合结构与合理的 viewBox""" for fname in self.core_showcase_files: fpath = os.path.join(self.showcases_dir, fname) with open(fpath, 'r', encoding='utf-8') as f: content = f.read() self.assertTrue(content.strip().startswith(''), f"{fname} 必须以 闭合") self.assertIn('viewBox', content, f"{fname} 必须指定 viewBox 属性以确保自适应") if __name__ == '__main__': unittest.main()