From 3f906f7a41a8fb455597a9189b588f258731447c Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 24 Dec 2021 14:20:05 +0800 Subject: [PATCH] update threshold for image merge --- src/plugins/nonebot_bison/post.py | 2 +- tests/test_merge_pic.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/plugins/nonebot_bison/post.py b/src/plugins/nonebot_bison/post.py index 9ef1136..8a77a3d 100644 --- a/src/plugins/nonebot_bison/post.py +++ b/src/plugins/nonebot_bison/post.py @@ -42,7 +42,7 @@ class Post: return Image.open(pic_buffer) def _check_image_square(self, size: tuple[int, int]) -> bool: - return abs(size[0] - size[1]) / size[0] < 0.01 + return abs(size[0] - size[1]) / size[0] < 0.05 async def _pic_merge(self) -> None: if len(self.pics) < 3: diff --git a/tests/test_merge_pic.py b/tests/test_merge_pic.py index 3ac9a15..6dcd2c2 100644 --- a/tests/test_merge_pic.py +++ b/tests/test_merge_pic.py @@ -21,6 +21,20 @@ merge_source_9 = [ "https://wx4.sinaimg.cn/large/0071VPLMgy1gq0vifc826j30rs4a64qs.jpg", "https://wx1.sinaimg.cn/large/0071VPLMgy1gq0vify21lj30rsbj71ld.jpg", ] +merge_source_9_2 = [ + 'https://wx2.sinaimg.cn/large/0071VPLMgy1gxo0eyycd7j30dw0dd3zk.jpg', + 'https://wx1.sinaimg.cn/large/0071VPLMgy1gxo0eyx6mhj30dw0ddjs8.jpg', + 'https://wx4.sinaimg.cn/large/0071VPLMgy1gxo0eyxf2bj30dw0dddh4.jpg', + 'https://wx3.sinaimg.cn/large/0071VPLMgy1gxo0ez1h5zj30dw0efwfs.jpg', + 'https://wx3.sinaimg.cn/large/0071VPLMgy1gxo0eyyku4j30dw0ef3zm.jpg', + 'https://wx1.sinaimg.cn/large/0071VPLMgy1gxo0ez0bjhj30dw0efabs.jpg', + 'https://wx4.sinaimg.cn/large/0071VPLMgy1gxo0ezdcafj30dw0dwacb.jpg', + 'https://wx1.sinaimg.cn/large/0071VPLMgy1gxo0ezg2g3j30dw0dwq51.jpg', + 'https://wx3.sinaimg.cn/large/0071VPLMgy1gxo0ez5oloj30dw0dw0uf.jpg', + 'https://wx4.sinaimg.cn/large/0071VPLMgy1gxo0fnk6stj30rs44ne81.jpg', + 'https://wx2.sinaimg.cn/large/0071VPLMgy1gxo0fohgcoj30rs3wpe81.jpg', + 'https://wx3.sinaimg.cn/large/0071VPLMgy1gxo0fpr6chj30rs3m1b29.jpg' + ] @pytest.mark.asyncio async def test_9_merge(plugin_module: 'nonebot_bison'): @@ -29,6 +43,13 @@ async def test_9_merge(plugin_module: 'nonebot_bison'): assert len(post.pics) == 5 await post.generate_messages() +@pytest.mark.asyncio +async def test_9_merge_2(plugin_module: 'nonebot_bison'): + post = plugin_module.post.Post('', '', '', pics=merge_source_9_2) + await post._pic_merge() + assert len(post.pics) == 4 + await post.generate_messages() + @pytest.mark.asyncio async def test_6_merge(plugin_module): post = plugin_module.post.Post('', '', '', pics=merge_source_9[0:6]+merge_source_9[9:])