"""qwen-image 客户端:响应解析与提示词拼装(无网络)。""" import unittest from utils import qwen_image_client as qic class TestQwenImageClient(unittest.TestCase): def test_extract_image_url(self): payload = { 'output': { 'choices': [ {'message': {'content': [{'image': 'https://example.com/a.png'}]}} ] } } self.assertEqual(qic._extract_image_url(payload), 'https://example.com/a.png') def test_extract_image_url_empty(self): self.assertIsNone(qic._extract_image_url({})) def test_build_attachment_prompt_truncates(self): long_body = 'x' * 2000 p = qic.build_attachment_figure_prompt('标题', long_body) self.assertLessEqual(len(p), 900) self.assertIn('标题', p) if __name__ == '__main__': unittest.main()