test_dump_graph_data.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest
  2. import unittest
  3. import json
  4. import os
  5. from community.dump_graph_data import get_props, get_entities, get_relationships
  6. class TestDumpGraphData(unittest.TestCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. cls.test_data_path = os.path.join(os.getcwd(), 'web', 'cached_data')
  10. os.makedirs(cls.test_data_path, exist_ok=True)
  11. def test_get_props(self):
  12. """测试属性获取方法,验证多属性合并逻辑"""
  13. props = get_props('1') # 使用真实节点ID
  14. self.assertIsInstance(props, dict)
  15. self.assertTrue(len(props) > 0)
  16. def test_entity_export(self):
  17. """验证实体导出的分页查询和JSON序列化"""
  18. get_entities()
  19. # 验证生成的实体文件
  20. with open(os.path.join(self.test_data_path, 'entities_med.json'), 'r', encoding='utf-8') as f:
  21. entities = json.load(f)
  22. self.assertTrue(len(entities) > 0)
  23. def test_relationship_chunking(self):
  24. """测试关系数据分块写入逻辑,验证每批处理1000条"""
  25. get_relationships()
  26. # 验证生成的关系文件
  27. file_count = len([f for f in os.listdir(self.test_data_path)
  28. if f.startswith('relationship_med_')])
  29. self.assertTrue(file_count > 0)
  30. #def tearDown(self):
  31. # 清理测试生成的文件
  32. #for f in os.listdir(self.test_data_path):
  33. #if f.startswith(('entities_med', 'relationship_med_')):
  34. #os.remove(os.path.join(self.test_data_path, f))
  35. if __name__ == '__main__':
  36. unittest.main()