1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
import unittest from pathlib import Path from generate_xmind import XMindGenerator
class TestXMindGenerator(unittest.TestCase): def setUp(self): self.generator = XMindGenerator() self.test_output = '/tmp/test.xmind' def test_generate_basic(self): """测试基础生成""" content = { 'id': 'root', 'title': '测试主题', 'children': [ {'id': 'c1', 'title': '子主题 1'}, {'id': 'c2', 'title': '子主题 2'} ] } output = self.generator.generate(content, self.test_output) self.assertTrue(Path(output).exists()) with zipfile.ZipFile(output, 'r') as zf: self.assertIn('content.xml', zf.namelist()) self.assertIn('styles.xml', zf.namelist()) def test_generate_with_styles(self): """测试带样式生成""" content = { 'id': 'root', 'title': '彩色主题', 'color': '#FF0000', 'children': [ {'id': 'c1', 'title': '红色子主题', 'color': '#FF0000'}, {'id': 'c2', 'title': '蓝色子主题', 'color': '#0000FF'} ] } output = self.generator.generate(content, self.test_output) with zipfile.ZipFile(output, 'r') as zf: styles = zf.read('styles.xml').decode() self.assertIn('#FF0000', styles) self.assertIn('#0000FF', styles) def test_open_in_xmind(self): """测试在 XMind 中打开(集成测试)""" import subprocess content = {'id': 'root', 'title': '集成测试'} output = self.generator.generate(content, self.test_output) result = subprocess.run( ['xmind', 'open', output], capture_output=True ) self.assertEqual(result.returncode, 0)
if __name__ == '__main__': unittest.main()
|