From 462013ac1e08c935ee4a1262c85d140588ee8e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Fri, 2 Sep 2022 14:59:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E5=88=A0=E9=99=A4=E6=97=A7?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E5=B9=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/apihelper/artifact.py | 3 +++ test/model/apihelper/test_artifact.py | 3 +++ test/model/test_base.py | 28 --------------------------- 3 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 test/model/test_base.py diff --git a/models/apihelper/artifact.py b/models/apihelper/artifact.py index 800a050..38e189a 100644 --- a/models/apihelper/artifact.py +++ b/models/apihelper/artifact.py @@ -44,6 +44,9 @@ class ArtifactOcrRate: def __init__(self): self.client = httpx.AsyncClient(headers=self.HEADERS) + async def close(self): + await self.client.aclose() + async def get_artifact_attr(self, photo_byte): b64_str = b64encode(photo_byte).decode() req = await self.client.post(self.OCR_URL, json={"image": b64_str}, timeout=8) diff --git a/test/model/apihelper/test_artifact.py b/test/model/apihelper/test_artifact.py index d749abb..4b48b07 100644 --- a/test/model/apihelper/test_artifact.py +++ b/test/model/apihelper/test_artifact.py @@ -21,6 +21,9 @@ class TestArtifact(IsolatedAsyncioTestCase): {'type': 'cd', 'name': '暴击伤害', 'value': '10.9%'}]} await self.artifact_rate.rate_artifact(artifact_attr) + async def asyncTearDown(self) -> None: + await self.artifact_rate.close() + if __name__ == "__main__": unittest.main() diff --git a/test/model/test_base.py b/test/model/test_base.py deleted file mode 100644 index 6cfe798..0000000 --- a/test/model/test_base.py +++ /dev/null @@ -1,28 +0,0 @@ -import json -import unittest - -from models.base import GameItem -from models.game.artifact import ArtifactInfo - - -class TestBase(unittest.TestCase): - def test_game_item(self): - test_dict = {"item_id": 0, "name": "攻击力", "type": "atk", "value": 2333} - test_json = json.dumps(test_dict) - test_game_item = GameItem(0, "攻击力", "atk", 2333) - new_json = test_game_item.to_json() - self.assertEqual(new_json, test_json) - - def test_artifact(self): - test_dict = {"item_id": 0, "name": "测试花", "pos": "测试属性", "star": 2333, - "sub_item": [{"item_id": 0, "name": "攻击力", "type": "atk", "value": 2333}], - "main_item": {"item_id": 0, "name": "攻击力", "type": "atk", "value": 2333}, "level": 2333} - test_json = json.dumps(test_dict) - test_game_item = GameItem(0, "攻击力", "atk", 2333) - test_artifact = ArtifactInfo(0, "测试花", 2333, test_game_item, "测试属性", 2333, [test_game_item]) - new_json = test_artifact.to_json() - self.assertEqual(test_json, new_json) - - -if __name__ == '__main__': - unittest.main()