import unittest import a_wordcloud import os import sys # 获取当前文件所在目录的绝对路径 current_dir = os.path.dirname(os.path.abspath(__file__)) # 获取 developed_code 目录的绝对路径,并添加到 sys.path 中 developed_code_path = os.path.abspath(os.path.join(current_dir, '..')) sys.path.append(developed_code_path) class TestAWordcloud(unittest.TestCase): def test_blue_color_func(self): color = a_wordcloud.blue_color_func() self.assertTrue(color.startswith("hsl(210, 100%,")) def test_wordcloud_generation(self): dm = { 'danmu': ["测试弹幕"] * 10 } with self.assertRaises(Exception): a_wordcloud.wordcloud_generation(dm) if __name__ == '__main__': unittest.main()