sync 8fdbc9196119e635985e99403d4b6f7ca7795701..0525340
Browse files- tests/test_v21_visual_forge.py +117 -0
tests/test_v21_visual_forge.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""V21 概念视觉锻造台测试:八步流水线 + --forge 集成。"""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import contextlib
|
| 6 |
+
import io
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import unittest
|
| 12 |
+
|
| 13 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 14 |
+
|
| 15 |
+
from holoaeon.concept_anatomy import CONCEPT_MAP # noqa: E402
|
| 16 |
+
from holoaeon import concept_visual_forge as forge_mod # noqa: E402
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class TestTextSearch(unittest.TestCase):
|
| 20 |
+
def test_hit_builtin(self):
|
| 21 |
+
s = forge_mod.text_search("经络")
|
| 22 |
+
self.assertTrue(s["hit"])
|
| 23 |
+
self.assertEqual(len(s["components"]), 8)
|
| 24 |
+
self.assertEqual(s["dimension"], "mechanism")
|
| 25 |
+
|
| 26 |
+
def test_miss_offtable(self):
|
| 27 |
+
s = forge_mod.text_search("圆珠笔")
|
| 28 |
+
self.assertFalse(s["hit"])
|
| 29 |
+
self.assertIn("圆珠笔", s["description"])
|
| 30 |
+
self.assertGreaterEqual(len(s["related"]), 0)
|
| 31 |
+
|
| 32 |
+
def test_all_builtin_searchable(self):
|
| 33 |
+
for c in CONCEPT_MAP:
|
| 34 |
+
self.assertTrue(forge_mod.text_search(c)["hit"], c)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class TestForgePipeline(unittest.TestCase):
|
| 38 |
+
def test_image_desc_v1(self):
|
| 39 |
+
d = forge_mod.image_desc_v1(forge_mod.text_search("经络"))
|
| 40 |
+
self.assertIn("主体", d)
|
| 41 |
+
|
| 42 |
+
def test_system_prompt_gen(self):
|
| 43 |
+
p = forge_mod.system_prompt_gen("主体:测试", "工业蓝图", "爆炸分解", "冷灰蓝")
|
| 44 |
+
self.assertIn("工业蓝图", p)
|
| 45 |
+
self.assertIn("爆炸分解", p)
|
| 46 |
+
self.assertIn("冷灰蓝", p)
|
| 47 |
+
|
| 48 |
+
def test_matrix_modify(self):
|
| 49 |
+
mx = forge_mod.matrix_modify("主体:测试")
|
| 50 |
+
self.assertEqual(mx["variant_count"], len(forge_mod.FORGE_MATRIX["style"]))
|
| 51 |
+
self.assertEqual(len(mx["variants"]), mx["variant_count"])
|
| 52 |
+
self.assertIn("工业蓝图", mx["variants"][0])
|
| 53 |
+
|
| 54 |
+
def test_optimize_prompt(self):
|
| 55 |
+
op = forge_mod.optimize_prompt("主体:测试")
|
| 56 |
+
self.assertIn("负面", op)
|
| 57 |
+
self.assertIn("确定性", op)
|
| 58 |
+
self.assertIn("只画概念映射表内元素", op)
|
| 59 |
+
|
| 60 |
+
def test_stylize_three_tiers(self):
|
| 61 |
+
st = forge_mod.stylize("主体:测试")
|
| 62 |
+
self.assertEqual(set(st.keys()), {"blueprint", "art_direction", "artistic"})
|
| 63 |
+
self.assertIn("工业蓝图制图", st["blueprint"])
|
| 64 |
+
self.assertIn("美术设定集", st["art_direction"])
|
| 65 |
+
self.assertIn("艺术创作", st["artistic"])
|
| 66 |
+
|
| 67 |
+
def test_forge_full_pipeline(self):
|
| 68 |
+
r = forge_mod.forge("经络")
|
| 69 |
+
self.assertEqual(r["input"], "经络")
|
| 70 |
+
self.assertTrue(r["step2_text_search"]["hit"])
|
| 71 |
+
self.assertEqual(r["step5_matrix"]["variant_count"], 6)
|
| 72 |
+
for k in ("blueprint", "art_direction", "artistic"):
|
| 73 |
+
self.assertIn(k, r["step7_9_stylized"])
|
| 74 |
+
|
| 75 |
+
def test_forge_offtable(self):
|
| 76 |
+
r = forge_mod.forge("圆珠笔")
|
| 77 |
+
self.assertFalse(r["step2_text_search"]["hit"])
|
| 78 |
+
self.assertIn("step6_optimized", r)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class TestForgeCli(unittest.TestCase):
|
| 82 |
+
@classmethod
|
| 83 |
+
def setUpClass(cls):
|
| 84 |
+
cls.repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 85 |
+
|
| 86 |
+
def test_module_main_stdout(self):
|
| 87 |
+
buf = io.StringIO()
|
| 88 |
+
with contextlib.redirect_stdout(buf):
|
| 89 |
+
rc = forge_mod.main(["经络"])
|
| 90 |
+
self.assertEqual(rc, 0)
|
| 91 |
+
d = json.loads(buf.getvalue())
|
| 92 |
+
self.assertTrue(d["step2_text_search"]["hit"])
|
| 93 |
+
|
| 94 |
+
def test_concept_anatomy_forge_integration(self):
|
| 95 |
+
r = subprocess.run(
|
| 96 |
+
[sys.executable, "-X", "utf8", "-m", "holoaeon.concept_anatomy",
|
| 97 |
+
"圆珠笔", "--forge"],
|
| 98 |
+
cwd=self.repo, capture_output=True, text=True, encoding="utf-8",
|
| 99 |
+
timeout=60)
|
| 100 |
+
self.assertEqual(r.returncode, 0)
|
| 101 |
+
d = json.loads(r.stdout)
|
| 102 |
+
self.assertIn("step7_9_stylized", d)
|
| 103 |
+
self.assertEqual(d["input"], "圆珠笔")
|
| 104 |
+
|
| 105 |
+
def test_forge_json_regression(self):
|
| 106 |
+
"""V19/V20 输出路径不破:--forge 不污染 --explain 与 JSON 解剖。"""
|
| 107 |
+
r = subprocess.run(
|
| 108 |
+
[sys.executable, "-X", "utf8", "-m", "holoaeon.concept_anatomy",
|
| 109 |
+
"经络", "--explain"],
|
| 110 |
+
cwd=self.repo, capture_output=True, text=True, encoding="utf-8",
|
| 111 |
+
timeout=60)
|
| 112 |
+
self.assertEqual(r.returncode, 0)
|
| 113 |
+
self.assertIn("一句话", r.stdout)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
unittest.main(verbosity=2)
|