From 913a01c4b057058498c34bcb7b46242ea9d9580e Mon Sep 17 00:00:00 2001 From: poppoppuppylove <431792974@qq.com> Date: Wed, 18 Sep 2024 22:12:32 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- developed_code/tests/__init__.py | 1 + developed_code/tests/a_wordcloud_test.py | 26 +++++++++++++++++++++ developed_code/tests/bvid_test.py | 25 ++++++++++++++++++++ developed_code/tests/to_allexcel_test.py | 29 ++++++++++++++++++++++++ developed_code/tests/to_danmu_test.py | 19 ++++++++++++++++ developed_code/tests/to_excel_test.py | 20 ++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 developed_code/tests/__init__.py create mode 100644 developed_code/tests/a_wordcloud_test.py create mode 100644 developed_code/tests/bvid_test.py create mode 100644 developed_code/tests/to_allexcel_test.py create mode 100644 developed_code/tests/to_danmu_test.py create mode 100644 developed_code/tests/to_excel_test.py diff --git a/developed_code/tests/__init__.py b/developed_code/tests/__init__.py new file mode 100644 index 0000000..cbefcd3 --- /dev/null +++ b/developed_code/tests/__init__.py @@ -0,0 +1 @@ +# This is the test package diff --git a/developed_code/tests/a_wordcloud_test.py b/developed_code/tests/a_wordcloud_test.py new file mode 100644 index 0000000..ff1054b --- /dev/null +++ b/developed_code/tests/a_wordcloud_test.py @@ -0,0 +1,26 @@ +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() diff --git a/developed_code/tests/bvid_test.py b/developed_code/tests/bvid_test.py new file mode 100644 index 0000000..0cbb83b --- /dev/null +++ b/developed_code/tests/bvid_test.py @@ -0,0 +1,25 @@ +import unittest +import bvid +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 TestBvid(unittest.TestCase): + + def test_get_source(self): + source = bvid.get_source(1) + self.assertTrue('bvid' in source) + + def test_extract_bv(self): + html = '{"bvid":"test_bvid","title":"test"}' + bvs = bvid.extract_bv(html) + self.assertIn("test_bvid", bvs) + +if __name__ == '__main__': + unittest.main() diff --git a/developed_code/tests/to_allexcel_test.py b/developed_code/tests/to_allexcel_test.py new file mode 100644 index 0000000..67e1495 --- /dev/null +++ b/developed_code/tests/to_allexcel_test.py @@ -0,0 +1,29 @@ +import unittest +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) + +# 打印 sys.path,确认路径是否正确 +print("sys.path:", sys.path) + +# 尝试导入 to_allexcel 模块 +try: + import to_allexcel +except ImportError as e: + print(f"ImportError: {e}") + +class TestToAllExcel(unittest.TestCase): + + def test_count_danmu(self): + danmu_list = ["测试弹幕"] * 5 + result = to_allexcel.count_danmu(danmu_list) + self.assertEqual(result["测试弹幕"], 5) + +if __name__ == '__main__': + unittest.main() diff --git a/developed_code/tests/to_danmu_test.py b/developed_code/tests/to_danmu_test.py new file mode 100644 index 0000000..cc58336 --- /dev/null +++ b/developed_code/tests/to_danmu_test.py @@ -0,0 +1,19 @@ +import unittest +import to_danmu +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 TestToDanmu(unittest.TestCase): + + def test_load_bv_numbers(self): + bv_numbers = to_danmu.load_bv_numbers("E:/Crawler/else/bv_numbers.txt") + self.assertIsInstance(bv_numbers, list) + +if __name__ == '__main__': + unittest.main() diff --git a/developed_code/tests/to_excel_test.py b/developed_code/tests/to_excel_test.py new file mode 100644 index 0000000..606602c --- /dev/null +++ b/developed_code/tests/to_excel_test.py @@ -0,0 +1,20 @@ +import unittest +import to_excel +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 TestToExcel(unittest.TestCase): + + def test_filter_and_count_danmu(self): + danmu_list = ["AI 是未来", "机器学习", "AI 是未来", "人工智能"] + result = to_excel.filter_and_count_danmu(danmu_list) + self.assertEqual(result["AI 是未来"], 2) + +if __name__ == '__main__': + unittest.main()