From 74b754f283dd3117f3f14f4642da69b1da50cb89 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Wed, 16 Jun 2021 09:24:11 +0800 Subject: [PATCH] move test --- test/init.py | 14 -------------- {test => tests}/__init__.py | 0 tests/conftest.py | 10 ++++++++++ tests/test_config_manager.py | 26 ++++++++++++++++++++++++++ {test => tests}/test_merge_pic.py | 11 ++++++++--- 5 files changed, 44 insertions(+), 17 deletions(-) delete mode 100644 test/init.py rename {test => tests}/__init__.py (100%) create mode 100644 tests/conftest.py create mode 100644 tests/test_config_manager.py rename {test => tests}/test_merge_pic.py (85%) diff --git a/test/init.py b/test/init.py deleted file mode 100644 index 1225ce9..0000000 --- a/test/init.py +++ /dev/null @@ -1,14 +0,0 @@ -import typing -if typing.TYPE_CHECKING: - import sys - sys.path.append('./src/plugins') - import nonebot_hk_reporter -import nonebot - -nonebot.init() -plugins = nonebot.load_plugins('src/plugins') -plugin = list(filter(lambda x: x.name == 'nonebot_hk_reporter', plugins))[0] -if typing.TYPE_CHECKING: - plugin_module : nonebot_hk_reporter = plugin.module -else: - plugin_module = plugin.module diff --git a/test/__init__.py b/tests/__init__.py similarity index 100% rename from test/__init__.py rename to tests/__init__.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..6673aeb --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest +import nonebot + +@pytest.fixture#(scope="module") +def plugin_module(tmpdir): + nonebot.init(hk_reporter_config_path=str(tmpdir)) + nonebot.load_plugins('src/plugins') + plugins = nonebot.get_loaded_plugins() + plugin = list(filter(lambda x: x.name == 'nonebot_hk_reporter', plugins))[0] + return plugin.module diff --git a/tests/test_config_manager.py b/tests/test_config_manager.py new file mode 100644 index 0000000..308aff7 --- /dev/null +++ b/tests/test_config_manager.py @@ -0,0 +1,26 @@ +import pytest +import typing + +if typing.TYPE_CHECKING: + import sys + sys.path.append('./src/plugins') + import nonebot_hk_reporter + +@pytest.fixture +def config(plugin_module): + plugin_module.config.start_up() + return plugin_module.config.Config() + +def test_create_and_get(config: 'nonebot_hk_reporter.config.Config', plugin_module: 'nonebot_hk_reporter'): + config.add_subscribe( + user='123', + user_type='group', + target='weibo_id', + target_name='weibo_name', + target_type='weibo', + cats=[], + tags=[]) + confs = config.list_subscribe('123', 'group') + assert(len(confs) == 1) + assert(config.target_user_cache['weibo']['weibo_id'] == \ + [plugin_module.types.User('123', 'group')]) diff --git a/test/test_merge_pic.py b/tests/test_merge_pic.py similarity index 85% rename from test/test_merge_pic.py rename to tests/test_merge_pic.py index 676ba66..48a6141 100644 --- a/test/test_merge_pic.py +++ b/tests/test_merge_pic.py @@ -1,5 +1,10 @@ import pytest -from .init import plugin_module +import typing + +if typing.TYPE_CHECKING: + import sys + sys.path.append('./src/plugins') + import nonebot_hk_reporter merge_source_9 = [ 'https://wx1.sinaimg.cn/large/0071VPLMgy1gq0vib7zooj30dx0dxmz5.jpg', @@ -18,13 +23,13 @@ merge_source_9 = [ ] @pytest.mark.asyncio -async def test_9_merge(): +async def test_9_merge(plugin_module: 'nonebot_hk_reporter'): post = plugin_module.post.Post('', '', '', pics=merge_source_9) await post._pic_merge() assert len(post.pics) == 5 @pytest.mark.asyncio -async def test_6_merge(): +async def test_6_merge(plugin_module): post = plugin_module.post.Post('', '', '', pics=merge_source_9[0:6]+merge_source_9[9:]) await post._pic_merge() assert len(post.pics) == 5