From e701247e8dde316ad5f26cb152abedb2813864c3 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Thu, 1 Aug 2024 16:44:14 +0800 Subject: [PATCH 1/7] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9C=80=E7=AE=80=E5=8D=95=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同时修复了 get_plugin_dir 的问题 --- nonebot_plugin_localstore/__init__.py | 6 +- poetry.lock | 426 +++++++++++++++++++- pyproject.toml | 9 + tests/__init__.py | 0 tests/conftest.py | 28 ++ tests/plugin/__init__.py | 34 ++ tests/plugin/plugins/sub_plugin/__init__.py | 26 ++ tests/test_get_plugin_dir.py | 45 +++ tests/utils.py | 81 ++++ 9 files changed, 640 insertions(+), 15 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/conftest.py create mode 100644 tests/plugin/__init__.py create mode 100644 tests/plugin/plugins/sub_plugin/__init__.py create mode 100644 tests/test_get_plugin_dir.py create mode 100644 tests/utils.py diff --git a/nonebot_plugin_localstore/__init__.py b/nonebot_plugin_localstore/__init__.py index 850212f..3e501c6 100644 --- a/nonebot_plugin_localstore/__init__.py +++ b/nonebot_plugin_localstore/__init__.py @@ -131,7 +131,7 @@ def _get_plugin_path(base_dir: Path, plugin: Plugin) -> Path: @_auto_create_dir def get_plugin_cache_dir() -> Path: - plugin = _try_get_caller_plugin(1) + plugin = _try_get_caller_plugin(2) return _get_plugin_path(BASE_CACHE_DIR, plugin) @@ -141,7 +141,7 @@ def get_plugin_cache_file(filename: str) -> Path: @_auto_create_dir def get_plugin_config_dir() -> Path: - plugin = _try_get_caller_plugin(1) + plugin = _try_get_caller_plugin(2) return _get_plugin_path(BASE_CONFIG_DIR, plugin) @@ -151,7 +151,7 @@ def get_plugin_config_file(filename: str) -> Path: @_auto_create_dir def get_plugin_data_dir() -> Path: - plugin = _try_get_caller_plugin(1) + plugin = _try_get_caller_plugin(2) return _get_plugin_path(BASE_DATA_DIR, plugin) diff --git a/poetry.lock b/poetry.lock index 0fe233d..e1047ec 100644 --- a/poetry.lock +++ b/poetry.lock @@ -11,6 +11,37 @@ files = [ {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, ] +[[package]] +name = "asgiref" +version = "3.8.1" +description = "ASGI specs, helper code, and adapters" +optional = false +python-versions = ">=3.8" +files = [ + {file = "asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47"}, + {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4", markers = "python_version < \"3.11\""} + +[package.extras] +tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] + +[[package]] +name = "async-asgi-testclient" +version = "1.4.11" +description = "Async client for testing ASGI web applications" +optional = false +python-versions = "*" +files = [ + {file = "async-asgi-testclient-1.4.11.tar.gz", hash = "sha256:4449ac85d512d661998ec61f91c9ae01851639611d748d81ae7f816736551792"}, +] + +[package.dependencies] +multidict = ">=4.0,<7.0" +requests = ">=2.21,<3.0" + [[package]] name = "black" version = "24.4.2" @@ -57,6 +88,17 @@ d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] uvloop = ["uvloop (>=0.15.2)"] +[[package]] +name = "certifi" +version = "2024.7.4" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.6" +files = [ + {file = "certifi-2024.7.4-py3-none-any.whl", hash = "sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90"}, + {file = "certifi-2024.7.4.tar.gz", hash = "sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b"}, +] + [[package]] name = "cfgv" version = "3.4.0" @@ -68,6 +110,105 @@ files = [ {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, ] +[[package]] +name = "charset-normalizer" +version = "3.3.2" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +optional = false +python-versions = ">=3.7.0" +files = [ + {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9063e24fdb1e498ab71cb7419e24622516c4a04476b17a2dab57e8baa30d6e03"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6897af51655e3691ff853668779c7bad41579facacf5fd7253b0133308cf000d"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1d3193f4a680c64b4b6a9115943538edb896edc190f0b222e73761716519268e"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cd70574b12bb8a4d2aaa0094515df2463cb429d8536cfb6c7ce983246983e5a6"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8465322196c8b4d7ab6d1e049e4c5cb460d0394da4a27d23cc242fbf0034b6b5"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9a8e9031d613fd2009c182b69c7b2c1ef8239a0efb1df3f7c8da66d5dd3d537"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:beb58fe5cdb101e3a055192ac291b7a21e3b7ef4f67fa1d74e331a7f2124341c"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:e06ed3eb3218bc64786f7db41917d4e686cc4856944f53d5bdf83a6884432e12"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:2e81c7b9c8979ce92ed306c249d46894776a909505d8f5a4ba55b14206e3222f"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:572c3763a264ba47b3cf708a44ce965d98555f618ca42c926a9c1616d8f34269"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-win32.whl", hash = "sha256:3d47fa203a7bd9c5b6cee4736ee84ca03b8ef23193c0d1ca99b5089f72645c73"}, + {file = "charset_normalizer-3.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:10955842570876604d404661fbccbc9c7e684caf432c09c715ec38fbae45ae09"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:802fe99cca7457642125a8a88a084cef28ff0cf9407060f7b93dca5aa25480db"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:573f6eac48f4769d667c4442081b1794f52919e7edada77495aaed9236d13a96"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:549a3a73da901d5bc3ce8d24e0600d1fa85524c10287f6004fbab87672bf3e1e"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f27273b60488abe721a075bcca6d7f3964f9f6f067c8c4c605743023d7d3944f"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1ceae2f17a9c33cb48e3263960dc5fc8005351ee19db217e9b1bb15d28c02574"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:65f6f63034100ead094b8744b3b97965785388f308a64cf8d7c34f2f2e5be0c4"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:753f10e867343b4511128c6ed8c82f7bec3bd026875576dfd88483c5c73b2fd8"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4a78b2b446bd7c934f5dcedc588903fb2f5eec172f3d29e52a9096a43722adfc"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e537484df0d8f426ce2afb2d0f8e1c3d0b114b83f8850e5f2fbea0e797bd82ae"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:eb6904c354526e758fda7167b33005998fb68c46fbc10e013ca97f21ca5c8887"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:deb6be0ac38ece9ba87dea880e438f25ca3eddfac8b002a2ec3d9183a454e8ae"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:4ab2fe47fae9e0f9dee8c04187ce5d09f48eabe611be8259444906793ab7cbce"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:80402cd6ee291dcb72644d6eac93785fe2c8b9cb30893c1af5b8fdd753b9d40f"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-win32.whl", hash = "sha256:7cd13a2e3ddeed6913a65e66e94b51d80a041145a026c27e6bb76c31a853c6ab"}, + {file = "charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:663946639d296df6a2bb2aa51b60a2454ca1cb29835324c640dafb5ff2131a77"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:0b2b64d2bb6d3fb9112bafa732def486049e63de9618b5843bcdd081d8144cd8"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:ddbb2551d7e0102e7252db79ba445cdab71b26640817ab1e3e3648dad515003b"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:55086ee1064215781fff39a1af09518bc9255b50d6333f2e4c74ca09fac6a8f6"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f4a014bc36d3c57402e2977dada34f9c12300af536839dc38c0beab8878f38a"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a10af20b82360ab00827f916a6058451b723b4e65030c5a18577c8b2de5b3389"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d756e44e94489e49571086ef83b2bb8ce311e730092d2c34ca8f7d925cb20aa"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90d558489962fd4918143277a773316e56c72da56ec7aa3dc3dbbe20fdfed15b"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ac7ffc7ad6d040517be39eb591cac5ff87416c2537df6ba3cba3bae290c0fed"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:7ed9e526742851e8d5cc9e6cf41427dfc6068d4f5a3bb03659444b4cabf6bc26"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:8bdb58ff7ba23002a4c5808d608e4e6c687175724f54a5dade5fa8c67b604e4d"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:6b3251890fff30ee142c44144871185dbe13b11bab478a88887a639655be1068"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_s390x.whl", hash = "sha256:b4a23f61ce87adf89be746c8a8974fe1c823c891d8f86eb218bb957c924bb143"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:efcb3f6676480691518c177e3b465bcddf57cea040302f9f4e6e191af91174d4"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-win32.whl", hash = "sha256:d965bba47ddeec8cd560687584e88cf699fd28f192ceb452d1d7ee807c5597b7"}, + {file = "charset_normalizer-3.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:96b02a3dc4381e5494fad39be677abcb5e6634bf7b4fa83a6dd3112607547001"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:95f2a5796329323b8f0512e09dbb7a1860c46a39da62ecb2324f116fa8fdc85c"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c002b4ffc0be611f0d9da932eb0f704fe2602a9a949d1f738e4c34c75b0863d5"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a981a536974bbc7a512cf44ed14938cf01030a99e9b3a06dd59578882f06f985"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3287761bc4ee9e33561a7e058c72ac0938c4f57fe49a09eae428fd88aafe7bb6"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42cb296636fcc8b0644486d15c12376cb9fa75443e00fb25de0b8602e64c1714"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0a55554a2fa0d408816b3b5cedf0045f4b8e1a6065aec45849de2d6f3f8e9786"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:c083af607d2515612056a31f0a8d9e0fcb5876b7bfc0abad3ecd275bc4ebc2d5"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:87d1351268731db79e0f8e745d92493ee2841c974128ef629dc518b937d9194c"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:bd8f7df7d12c2db9fab40bdd87a7c09b1530128315d047a086fa3ae3435cb3a8"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:c180f51afb394e165eafe4ac2936a14bee3eb10debc9d9e4db8958fe36afe711"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8c622a5fe39a48f78944a87d4fb8a53ee07344641b0562c540d840748571b811"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-win32.whl", hash = "sha256:db364eca23f876da6f9e16c9da0df51aa4f104a972735574842618b8c6d999d4"}, + {file = "charset_normalizer-3.3.2-cp37-cp37m-win_amd64.whl", hash = "sha256:86216b5cee4b06df986d214f664305142d9c76df9b6512be2738aa72a2048f99"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:6463effa3186ea09411d50efc7d85360b38d5f09b870c48e4600f63af490e56a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6c4caeef8fa63d06bd437cd4bdcf3ffefe6738fb1b25951440d80dc7df8c03ac"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:37e55c8e51c236f95b033f6fb391d7d7970ba5fe7ff453dad675e88cf303377a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fb69256e180cb6c8a894fee62b3afebae785babc1ee98b81cdf68bbca1987f33"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ae5f4161f18c61806f411a13b0310bea87f987c7d2ecdbdaad0e94eb2e404238"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b2b0a0c0517616b6869869f8c581d4eb2dd83a4d79e0ebcb7d373ef9956aeb0a"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:45485e01ff4d3630ec0d9617310448a8702f70e9c01906b0d0118bdf9d124cf2"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eb00ed941194665c332bf8e078baf037d6c35d7c4f3102ea2d4f16ca94a26dc8"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:2127566c664442652f024c837091890cb1942c30937add288223dc895793f898"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:a50aebfa173e157099939b17f18600f72f84eed3049e743b68ad15bd69b6bf99"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:4d0d1650369165a14e14e1e47b372cfcb31d6ab44e6e33cb2d4e57265290044d"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:923c0c831b7cfcb071580d3f46c4baf50f174be571576556269530f4bbd79d04"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-win32.whl", hash = "sha256:6ef1d82a3af9d3eecdba2321dc1b3c238245d890843e040e41e470ffa64c3e25"}, + {file = "charset_normalizer-3.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:eb8821e09e916165e160797a6c17edda0679379a4be5c716c260e836e122f54b"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:c235ebd9baae02f1b77bcea61bce332cb4331dc3617d254df3323aa01ab47bd4"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:5b4c145409bef602a690e7cfad0a15a55c13320ff7a3ad7ca59c13bb8ba4d45d"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:68d1f8a9e9e37c1223b656399be5d6b448dea850bed7d0f87a8311f1ff3dabb0"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:22afcb9f253dac0696b5a4be4a1c0f8762f8239e21b99680099abd9b2b1b2269"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e27ad930a842b4c5eb8ac0016b0a54f5aebbe679340c26101df33424142c143c"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1f79682fbe303db92bc2b1136016a38a42e835d932bab5b3b1bfcfbf0640e519"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b261ccdec7821281dade748d088bb6e9b69e6d15b30652b74cbbac25e280b796"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:122c7fa62b130ed55f8f285bfd56d5f4b4a5b503609d181f9ad85e55c89f4185"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d0eccceffcb53201b5bfebb52600a5fb483a20b61da9dbc885f8b103cbe7598c"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9f96df6923e21816da7e0ad3fd47dd8f94b2a5ce594e00677c0013018b813458"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:7f04c839ed0b6b98b1a7501a002144b76c18fb1c1850c8b98d458ac269e26ed2"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:34d1c8da1e78d2e001f363791c98a272bb734000fcef47a491c1e3b0505657a8"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-win32.whl", hash = "sha256:aed38f6e4fb3f5d6bf81bfa990a07806be9d83cf7bacef998ab1a9bd660a581f"}, + {file = "charset_normalizer-3.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:b01b88d45a6fcb69667cd6d2f7a9aeb4bf53760d7fc536bf679ec94fe9f3ff3d"}, + {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, +] + [[package]] name = "click" version = "8.1.7" @@ -93,6 +234,73 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "coverage" +version = "7.6.0" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "coverage-7.6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dff044f661f59dace805eedb4a7404c573b6ff0cdba4a524141bc63d7be5c7fd"}, + {file = "coverage-7.6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a8659fd33ee9e6ca03950cfdcdf271d645cf681609153f218826dd9805ab585c"}, + {file = "coverage-7.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7792f0ab20df8071d669d929c75c97fecfa6bcab82c10ee4adb91c7a54055463"}, + {file = "coverage-7.6.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d4b3cd1ca7cd73d229487fa5caca9e4bc1f0bca96526b922d61053ea751fe791"}, + {file = "coverage-7.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e7e128f85c0b419907d1f38e616c4f1e9f1d1b37a7949f44df9a73d5da5cd53c"}, + {file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a94925102c89247530ae1dab7dc02c690942566f22e189cbd53579b0693c0783"}, + {file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:dcd070b5b585b50e6617e8972f3fbbee786afca71b1936ac06257f7e178f00f6"}, + {file = "coverage-7.6.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:d50a252b23b9b4dfeefc1f663c568a221092cbaded20a05a11665d0dbec9b8fb"}, + {file = "coverage-7.6.0-cp310-cp310-win32.whl", hash = "sha256:0e7b27d04131c46e6894f23a4ae186a6a2207209a05df5b6ad4caee6d54a222c"}, + {file = "coverage-7.6.0-cp310-cp310-win_amd64.whl", hash = "sha256:54dece71673b3187c86226c3ca793c5f891f9fc3d8aa183f2e3653da18566169"}, + {file = "coverage-7.6.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c7b525ab52ce18c57ae232ba6f7010297a87ced82a2383b1afd238849c1ff933"}, + {file = "coverage-7.6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bea27c4269234e06f621f3fac3925f56ff34bc14521484b8f66a580aacc2e7d"}, + {file = "coverage-7.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed8d1d1821ba5fc88d4a4f45387b65de52382fa3ef1f0115a4f7a20cdfab0e94"}, + {file = "coverage-7.6.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:01c322ef2bbe15057bc4bf132b525b7e3f7206f071799eb8aa6ad1940bcf5fb1"}, + {file = "coverage-7.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:03cafe82c1b32b770a29fd6de923625ccac3185a54a5e66606da26d105f37dac"}, + {file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0d1b923fc4a40c5832be4f35a5dab0e5ff89cddf83bb4174499e02ea089daf57"}, + {file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:4b03741e70fb811d1a9a1d75355cf391f274ed85847f4b78e35459899f57af4d"}, + {file = "coverage-7.6.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a73d18625f6a8a1cbb11eadc1d03929f9510f4131879288e3f7922097a429f63"}, + {file = "coverage-7.6.0-cp311-cp311-win32.whl", hash = "sha256:65fa405b837060db569a61ec368b74688f429b32fa47a8929a7a2f9b47183713"}, + {file = "coverage-7.6.0-cp311-cp311-win_amd64.whl", hash = "sha256:6379688fb4cfa921ae349c76eb1a9ab26b65f32b03d46bb0eed841fd4cb6afb1"}, + {file = "coverage-7.6.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f7db0b6ae1f96ae41afe626095149ecd1b212b424626175a6633c2999eaad45b"}, + {file = "coverage-7.6.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:bbdf9a72403110a3bdae77948b8011f644571311c2fb35ee15f0f10a8fc082e8"}, + {file = "coverage-7.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9cc44bf0315268e253bf563f3560e6c004efe38f76db03a1558274a6e04bf5d5"}, + {file = "coverage-7.6.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:da8549d17489cd52f85a9829d0e1d91059359b3c54a26f28bec2c5d369524807"}, + {file = "coverage-7.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0086cd4fc71b7d485ac93ca4239c8f75732c2ae3ba83f6be1c9be59d9e2c6382"}, + {file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:1fad32ee9b27350687035cb5fdf9145bc9cf0a094a9577d43e909948ebcfa27b"}, + {file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:044a0985a4f25b335882b0966625270a8d9db3d3409ddc49a4eb00b0ef5e8cee"}, + {file = "coverage-7.6.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:76d5f82213aa78098b9b964ea89de4617e70e0d43e97900c2778a50856dac605"}, + {file = "coverage-7.6.0-cp312-cp312-win32.whl", hash = "sha256:3c59105f8d58ce500f348c5b56163a4113a440dad6daa2294b5052a10db866da"}, + {file = "coverage-7.6.0-cp312-cp312-win_amd64.whl", hash = "sha256:ca5d79cfdae420a1d52bf177de4bc2289c321d6c961ae321503b2ca59c17ae67"}, + {file = "coverage-7.6.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d39bd10f0ae453554798b125d2f39884290c480f56e8a02ba7a6ed552005243b"}, + {file = "coverage-7.6.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:beb08e8508e53a568811016e59f3234d29c2583f6b6e28572f0954a6b4f7e03d"}, + {file = "coverage-7.6.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b2e16f4cd2bc4d88ba30ca2d3bbf2f21f00f382cf4e1ce3b1ddc96c634bc48ca"}, + {file = "coverage-7.6.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6616d1c9bf1e3faea78711ee42a8b972367d82ceae233ec0ac61cc7fec09fa6b"}, + {file = "coverage-7.6.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ad4567d6c334c46046d1c4c20024de2a1c3abc626817ae21ae3da600f5779b44"}, + {file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:d17c6a415d68cfe1091d3296ba5749d3d8696e42c37fca5d4860c5bf7b729f03"}, + {file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:9146579352d7b5f6412735d0f203bbd8d00113a680b66565e205bc605ef81bc6"}, + {file = "coverage-7.6.0-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:cdab02a0a941af190df8782aafc591ef3ad08824f97850b015c8c6a8b3877b0b"}, + {file = "coverage-7.6.0-cp38-cp38-win32.whl", hash = "sha256:df423f351b162a702c053d5dddc0fc0ef9a9e27ea3f449781ace5f906b664428"}, + {file = "coverage-7.6.0-cp38-cp38-win_amd64.whl", hash = "sha256:f2501d60d7497fd55e391f423f965bbe9e650e9ffc3c627d5f0ac516026000b8"}, + {file = "coverage-7.6.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7221f9ac9dad9492cecab6f676b3eaf9185141539d5c9689d13fd6b0d7de840c"}, + {file = "coverage-7.6.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ddaaa91bfc4477d2871442bbf30a125e8fe6b05da8a0015507bfbf4718228ab2"}, + {file = "coverage-7.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c4cbe651f3904e28f3a55d6f371203049034b4ddbce65a54527a3f189ca3b390"}, + {file = "coverage-7.6.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:831b476d79408ab6ccfadaaf199906c833f02fdb32c9ab907b1d4aa0713cfa3b"}, + {file = "coverage-7.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:46c3d091059ad0b9c59d1034de74a7f36dcfa7f6d3bde782c49deb42438f2450"}, + {file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:4d5fae0a22dc86259dee66f2cc6c1d3e490c4a1214d7daa2a93d07491c5c04b6"}, + {file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:07ed352205574aad067482e53dd606926afebcb5590653121063fbf4e2175166"}, + {file = "coverage-7.6.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:49c76cdfa13015c4560702574bad67f0e15ca5a2872c6a125f6327ead2b731dd"}, + {file = "coverage-7.6.0-cp39-cp39-win32.whl", hash = "sha256:482855914928c8175735a2a59c8dc5806cf7d8f032e4820d52e845d1f731dca2"}, + {file = "coverage-7.6.0-cp39-cp39-win_amd64.whl", hash = "sha256:543ef9179bc55edfd895154a51792b01c017c87af0ebaae092720152e19e42ca"}, + {file = "coverage-7.6.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:6fe885135c8a479d3e37a7aae61cbd3a0fb2deccb4dda3c25f92a49189f766d6"}, + {file = "coverage-7.6.0.tar.gz", hash = "sha256:289cc803fa1dc901f84701ac10c9ee873619320f2f9aff38794db4a4a0268d51"}, +] + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli"] + [[package]] name = "distlib" version = "0.3.8" @@ -104,6 +312,34 @@ files = [ {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, ] +[[package]] +name = "exceptiongroup" +version = "1.2.2" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, + {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "execnet" +version = "2.1.1" +description = "execnet: rapid multi-Python deployment" +optional = false +python-versions = ">=3.8" +files = [ + {file = "execnet-2.1.1-py3-none-any.whl", hash = "sha256:26dee51f1b80cebd6d0ca8e74dd8745419761d3bef34163928cbebbdc4749fdc"}, + {file = "execnet-2.1.1.tar.gz", hash = "sha256:5189b52c6121c24feae288166ab41b32549c7e2348652736540b9e6e7d4e72e3"}, +] + +[package.extras] +testing = ["hatch", "pre-commit", "pytest", "tox"] + [[package]] name = "filelock" version = "3.15.4" @@ -145,6 +381,17 @@ files = [ {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + [[package]] name = "isort" version = "5.13.2" @@ -326,6 +573,24 @@ httpx = ["httpx[http2] (>=0.20.0,<1.0.0)"] quart = ["Quart (>=0.18.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)"] websockets = ["websockets (>=10.0)"] +[[package]] +name = "nonebug" +version = "0.3.7" +description = "nonebot2 test framework" +optional = false +python-versions = "<4.0,>=3.8" +files = [ + {file = "nonebug-0.3.7-py3-none-any.whl", hash = "sha256:c39f462aafe20660602a8b789a575db6c9346ab5b6f1985eb9d98b861528299a"}, + {file = "nonebug-0.3.7.tar.gz", hash = "sha256:8a75183400681f34eafc7caa2bb6dd511c3b5660c59264f1c379a088c7ac2247"}, +] + +[package.dependencies] +asgiref = ">=3.4.0,<4.0.0" +async-asgi-testclient = ">=1.4.8,<2.0.0" +nonebot2 = ">=2.2.0,<3.0.0" +pytest = ">=7.0.0,<9.0.0" +typing-extensions = ">=4.0.0,<5.0.0" + [[package]] name = "nonemoji" version = "0.1.4" @@ -392,6 +657,21 @@ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx- test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] type = ["mypy (>=1.8)"] +[[package]] +name = "pluggy" +version = "1.5.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pre-commit" version = "3.8.0" @@ -558,6 +838,101 @@ files = [ {file = "pygtrie-2.5.0.tar.gz", hash = "sha256:203514ad826eb403dab1d2e2ddd034e0d1534bbe4dbe0213bb0593f66beba4e2"}, ] +[[package]] +name = "pytest" +version = "8.3.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-8.3.2-py3-none-any.whl", hash = "sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5"}, + {file = "pytest-8.3.2.tar.gz", hash = "sha256:c132345d12ce551242c87269de812483f5bcc87cdbb4722e48487ba194f9fdce"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=1.5,<2" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} + +[package.extras] +dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "pytest-asyncio" +version = "0.23.8" +description = "Pytest support for asyncio" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest_asyncio-0.23.8-py3-none-any.whl", hash = "sha256:50265d892689a5faefb84df80819d1ecef566eb3549cf915dfb33569359d1ce2"}, + {file = "pytest_asyncio-0.23.8.tar.gz", hash = "sha256:759b10b33a6dc61cce40a8bd5205e302978bbbcc00e279a8b61d9a6a3c82e4d3"}, +] + +[package.dependencies] +pytest = ">=7.0.0,<9" + +[package.extras] +docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] + +[[package]] +name = "pytest-cov" +version = "5.0.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, + {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] + +[[package]] +name = "pytest-mock" +version = "3.14.0" +description = "Thin-wrapper around the mock package for easier use with pytest" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"}, + {file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"}, +] + +[package.dependencies] +pytest = ">=6.2.5" + +[package.extras] +dev = ["pre-commit", "pytest-asyncio", "tox"] + +[[package]] +name = "pytest-xdist" +version = "3.6.1" +description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest_xdist-3.6.1-py3-none-any.whl", hash = "sha256:9ed4adfb68a016610848639bb7e02c9352d5d9f03d04809919e2dafc3be4cca7"}, + {file = "pytest_xdist-3.6.1.tar.gz", hash = "sha256:ead156a4db231eec769737f57668ef58a2084a34b2e55c4a8fa20d861107300d"}, +] + +[package.dependencies] +execnet = ">=2.1" +pytest = ">=7.0.0" + +[package.extras] +psutil = ["psutil (>=3.0)"] +setproctitle = ["setproctitle"] +testing = ["filelock"] + [[package]] name = "python-dotenv" version = "1.0.1" @@ -584,7 +959,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -592,16 +966,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -618,7 +984,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -626,12 +991,32 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, ] +[[package]] +name = "requests" +version = "2.32.3" +description = "Python HTTP for Humans." +optional = false +python-versions = ">=3.8" +files = [ + {file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"}, + {file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"}, +] + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<4" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<3" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + [[package]] name = "ruff" version = "0.5.5" @@ -681,6 +1066,23 @@ files = [ {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, ] +[[package]] +name = "urllib3" +version = "2.2.2" +description = "HTTP library with thread-safe connection pooling, file post, and more." +optional = false +python-versions = ">=3.8" +files = [ + {file = "urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472"}, + {file = "urllib3-2.2.2.tar.gz", hash = "sha256:dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168"}, +] + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] +h2 = ["h2 (>=4,<5)"] +socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] +zstd = ["zstandard (>=0.18.0)"] + [[package]] name = "virtualenv" version = "20.26.3" @@ -832,4 +1234,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "25607a40abcdefeec064cf652b4d64ccecee1091d35602771573355abe531445" +content-hash = "a6dfbd87181d1fb0038db1f78a5377a5954484209bce112b0aa5a8537c616bae" diff --git a/pyproject.toml b/pyproject.toml index 062bbfd..68ea899 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,11 @@ isort = "^5.10.1" black = "^24.0.0" nonemoji = "^0.1.2" pre-commit = "^3.5.0" +nonebug = "^0.3.7" +pytest-asyncio = "^0.23.8" +pytest-cov = "^5.0.0" +pytest-xdist = "^3.6.1" +pytest-mock = "^3.14.0" [tool.poetry.plugins.nb_scripts] localstore = "nonebot_plugin_localstore.script:main" @@ -87,3 +92,7 @@ disableBytesTypePromotions = true [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +addopts = ["--import-mode=importlib"] +asyncio_mode = "auto" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..bcc3592 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,28 @@ +from pathlib import Path + +import pytest +import nonebot +from nonebug.app import App +from pytest_mock import MockerFixture +from nonebug import NONEBOT_INIT_KWARGS + + +def pytest_configure(config: pytest.Config) -> None: + config.stash[NONEBOT_INIT_KWARGS] = { + "driver": "~none", + } + + +@pytest.fixture(scope="session") +def _load_plugin(nonebug_init: None): + nonebot.load_plugin("tests.plugin") + + +@pytest.fixture +def app(_load_plugin: None, tmp_path: Path, mocker: MockerFixture): + # 插件数据目录 + mocker.patch("nonebot_plugin_localstore.BASE_DATA_DIR", tmp_path / "data") + mocker.patch("nonebot_plugin_localstore.BASE_CACHE_DIR", tmp_path / "cache") + mocker.patch("nonebot_plugin_localstore.BASE_CONFIG_DIR", tmp_path / "config") + + return App() diff --git a/tests/plugin/__init__.py b/tests/plugin/__init__.py new file mode 100644 index 0000000..1ffa0f4 --- /dev/null +++ b/tests/plugin/__init__.py @@ -0,0 +1,34 @@ +from pathlib import Path + +import nonebot +from nonebot.adapters import Message +from nonebot.params import CommandArg +from nonebot import require, on_command + +require("nonebot_plugin_localstore") +from nonebot_plugin_localstore import ( + get_plugin_data_dir, + get_plugin_cache_dir, + get_plugin_config_dir, +) + +plugin_cmd = on_command("plugin") + + +@plugin_cmd.handle() +async def plugin_handle(args: Message = CommandArg()): + type_ = args.extract_plain_text() + + if type_ == "cache": + cache_dir = get_plugin_cache_dir() + await plugin_cmd.finish(f"{cache_dir}") + elif type_ == "config": + config_dir = get_plugin_config_dir() + await plugin_cmd.finish(f"{config_dir}") + elif type_ == "data": + data_dir = get_plugin_data_dir() + await plugin_cmd.finish(f"{data_dir}") + + +_sub_plugins = set() +_sub_plugins |= nonebot.load_plugins(str((Path(__file__).parent / "plugins").resolve())) diff --git a/tests/plugin/plugins/sub_plugin/__init__.py b/tests/plugin/plugins/sub_plugin/__init__.py new file mode 100644 index 0000000..215971b --- /dev/null +++ b/tests/plugin/plugins/sub_plugin/__init__.py @@ -0,0 +1,26 @@ +from nonebot import on_command +from nonebot.adapters import Message +from nonebot.params import CommandArg + +from nonebot_plugin_localstore import ( + get_plugin_data_dir, + get_plugin_cache_dir, + get_plugin_config_dir, +) + +sub_plugin_cmd = on_command("sub_plugin") + + +@sub_plugin_cmd.handle() +async def plugin_handle(args: Message = CommandArg()): + type_ = args.extract_plain_text() + + if type_ == "cache": + cache_dir = get_plugin_cache_dir() + await sub_plugin_cmd.finish(f"{cache_dir}") + elif type_ == "config": + config_dir = get_plugin_config_dir() + await sub_plugin_cmd.finish(f"{config_dir}") + elif type_ == "data": + data_dir = get_plugin_data_dir() + await sub_plugin_cmd.finish(f"{data_dir}") diff --git a/tests/test_get_plugin_dir.py b/tests/test_get_plugin_dir.py new file mode 100644 index 0000000..42e240e --- /dev/null +++ b/tests/test_get_plugin_dir.py @@ -0,0 +1,45 @@ +from pathlib import Path + +from nonebug import App + +from tests.utils import make_fake_event, make_fake_message + + +async def test_plugin_dir(app: App, tmp_path: Path): + """获取到插件的缓存目录、配置目录和数据目录""" + from tests.plugin import plugin_cmd + + async with app.test_matcher(plugin_cmd) as ctx: + bot = ctx.create_bot() + message = make_fake_message()("/plugin cache") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "cache" / "plugin"), + True, + ) + ctx.should_finished(plugin_cmd) + + message = make_fake_message()("/plugin config") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "config" / "plugin"), + True, + ) + ctx.should_finished(plugin_cmd) + + message = make_fake_message()("/plugin data") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "data" / "plugin"), + True, + ) + ctx.should_finished(plugin_cmd) diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..b663e1c --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,81 @@ +from typing import TYPE_CHECKING, Optional + +from pydantic import create_model + +if TYPE_CHECKING: + from nonebot.adapters import Event, Message + + +def make_fake_message() -> type["Message"]: + from nonebot.adapters import Message, MessageSegment + + class FakeMessageSegment(MessageSegment): + @classmethod + def get_message_class(cls): + return FakeMessage + + def __str__(self) -> str: + return self.data["text"] if self.type == "text" else f"[fake:{self.type}]" + + @classmethod + def text(cls, text: str): + return cls("text", {"text": text}) + + @classmethod + def image(cls, url: str): + return cls("image", {"url": url}) + + def is_text(self) -> bool: + return self.type == "text" + + class FakeMessage(Message): + @classmethod + def get_segment_class(cls): + return FakeMessageSegment + + @staticmethod + def _construct(msg: str): + yield FakeMessageSegment.text(msg) + + return FakeMessage + + +def make_fake_event( + _type: str = "message", + _name: str = "test", + _description: str = "test", + _user_id: str = "test", + _session_id: str = "test", + _message: Optional["Message"] = None, + _to_me: bool = True, + **fields, +) -> type["Event"]: + from nonebot.adapters import Event + + _Fake = create_model("_Fake", __base__=Event, **fields) + + class FakeEvent(_Fake): + def get_type(self) -> str: + return _type + + def get_event_name(self) -> str: + return _name + + def get_event_description(self) -> str: + return _description + + def get_user_id(self) -> str: + return _user_id + + def get_session_id(self) -> str: + return _session_id + + def get_message(self) -> "Message": + if _message is not None: + return _message + raise NotImplementedError + + def is_tome(self) -> bool: + return _to_me + + return FakeEvent From cac12fa556f1bc1ff220652d69d98fa00a6a1a19 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Thu, 1 Aug 2024 16:47:11 +0800 Subject: [PATCH 2/7] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AD=90=E6=8F=92=E4=BB=B6=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_get_plugin_dir.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_get_plugin_dir.py b/tests/test_get_plugin_dir.py index 42e240e..8729151 100644 --- a/tests/test_get_plugin_dir.py +++ b/tests/test_get_plugin_dir.py @@ -43,3 +43,43 @@ async def test_plugin_dir(app: App, tmp_path: Path): True, ) ctx.should_finished(plugin_cmd) + + +async def test_sub_plugin_dir(app: App, tmp_path: Path): + """获取到子插件的缓存目录、配置目录和数据目录""" + from tests.plugin.plugins.sub_plugin import sub_plugin_cmd + + async with app.test_matcher(sub_plugin_cmd) as ctx: + bot = ctx.create_bot() + message = make_fake_message()("/sub_plugin cache") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "cache" / "plugin" / "sub_plugin"), + True, + ) + ctx.should_finished(sub_plugin_cmd) + + message = make_fake_message()("/sub_plugin config") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "config" / "plugin" / "sub_plugin"), + True, + ) + ctx.should_finished(sub_plugin_cmd) + + message = make_fake_message()("/sub_plugin data") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "data" / "plugin" / "sub_plugin"), + True, + ) + ctx.should_finished(sub_plugin_cmd) From 9f2f0c64ab1842f8f36043d1b5a359cdfa018945 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Thu, 1 Aug 2024 17:27:29 +0800 Subject: [PATCH 3/7] =?UTF-8?q?:construction=5Fworker:=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20codecov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codecov.yml | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/codecov.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..3288444 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,49 @@ +name: Code Coverage + +on: + push: + branches: + - "main" + pull_request: + +jobs: + test: + name: Test Coverage + runs-on: ${{ matrix.os }} + concurrency: + group: test-coverage-${{ github.ref }}-${{ matrix.os }}-${{ matrix.python-version }} + cancel-in-progress: true + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + os: [ubuntu-latest, windows-latest, macos-latest] + env: + OS: ${{ matrix.os }} + PYTHON_VERSION: ${{ matrix.python-version }} + + steps: + - uses: actions/checkout@v4 + + - name: Install poetry + run: pipx install poetry + + - name: Setup Python environment + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'poetry' + + - name: Install dependencies + run: | + poetry install + + - name: Run Pytest + run: | + poetry run pytest --cov=./nonebot_plugin_localstore --cov-report=xml -n auto + + - name: Upload coverage report + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + env_vars: OS,PYTHON_VERSION From 6b06538c9ff3ac6ddd9279e64f56a6d6b3ae1239 Mon Sep 17 00:00:00 2001 From: uy_sun Date: Thu, 1 Aug 2024 17:49:58 +0800 Subject: [PATCH 4/7] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20plugin=5Ffile=20=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_localstore/__init__.py | 25 +++--- tests/plugin/__init__.py | 21 +++++ tests/plugin/plugins/sub_plugin/__init__.py | 21 +++++ tests/test_get_plugin_file.py | 85 +++++++++++++++++++++ 4 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 tests/test_get_plugin_file.py diff --git a/nonebot_plugin_localstore/__init__.py b/nonebot_plugin_localstore/__init__.py index 3e501c6..87ecec4 100644 --- a/nonebot_plugin_localstore/__init__.py +++ b/nonebot_plugin_localstore/__init__.py @@ -93,33 +93,28 @@ def get_data_file(plugin_name: Optional[str], filename: str) -> Path: return get_data_dir(plugin_name) / filename -def _get_caller_plugin(depth: int = 0) -> Optional[Plugin]: +def _get_caller_plugin() -> Optional[Plugin]: current_frame = inspect.currentframe() if current_frame is None: return None - # skip depth of frames - frame = current_frame - while depth > 0: - frame = frame.f_back - if frame is None: - raise ValueError("Depth out of range") - depth -= 1 - # find plugin + frame = current_frame while frame := frame.f_back: module_name = (module := inspect.getmodule(frame)) and module.__name__ if module_name is None: return None - if plugin := get_plugin_by_module_name(module_name): + # skip nonebot_plugin_localstore it self + plugin = get_plugin_by_module_name(module_name) + if plugin and plugin.id_ != "nonebot_plugin_localstore": return plugin return None -def _try_get_caller_plugin(depth: int = 0) -> Plugin: - if plugin := _get_caller_plugin(depth + 1): +def _try_get_caller_plugin() -> Plugin: + if plugin := _get_caller_plugin(): return plugin raise RuntimeError("Cannot detect caller plugin") @@ -131,7 +126,7 @@ def _get_plugin_path(base_dir: Path, plugin: Plugin) -> Path: @_auto_create_dir def get_plugin_cache_dir() -> Path: - plugin = _try_get_caller_plugin(2) + plugin = _try_get_caller_plugin() return _get_plugin_path(BASE_CACHE_DIR, plugin) @@ -141,7 +136,7 @@ def get_plugin_cache_file(filename: str) -> Path: @_auto_create_dir def get_plugin_config_dir() -> Path: - plugin = _try_get_caller_plugin(2) + plugin = _try_get_caller_plugin() return _get_plugin_path(BASE_CONFIG_DIR, plugin) @@ -151,7 +146,7 @@ def get_plugin_config_file(filename: str) -> Path: @_auto_create_dir def get_plugin_data_dir() -> Path: - plugin = _try_get_caller_plugin(2) + plugin = _try_get_caller_plugin() return _get_plugin_path(BASE_DATA_DIR, plugin) diff --git a/tests/plugin/__init__.py b/tests/plugin/__init__.py index 1ffa0f4..95f4071 100644 --- a/tests/plugin/__init__.py +++ b/tests/plugin/__init__.py @@ -9,7 +9,10 @@ from nonebot_plugin_localstore import ( get_plugin_data_dir, get_plugin_cache_dir, + get_plugin_data_file, + get_plugin_cache_file, get_plugin_config_dir, + get_plugin_config_file, ) plugin_cmd = on_command("plugin") @@ -30,5 +33,23 @@ async def plugin_handle(args: Message = CommandArg()): await plugin_cmd.finish(f"{data_dir}") +plugin_file_cmd = on_command("plugin_file") + + +@plugin_file_cmd.handle() +async def plugin_file_handle(args: Message = CommandArg()): + type_, filename = args.extract_plain_text().split() + + if type_ == "cache": + cache_file = get_plugin_cache_file(filename) + await plugin_file_cmd.finish(f"{cache_file}") + elif type_ == "config": + config_file = get_plugin_config_file(filename) + await plugin_file_cmd.finish(f"{config_file}") + elif type_ == "data": + data_file = get_plugin_data_file(filename) + await plugin_file_cmd.finish(f"{data_file}") + + _sub_plugins = set() _sub_plugins |= nonebot.load_plugins(str((Path(__file__).parent / "plugins").resolve())) diff --git a/tests/plugin/plugins/sub_plugin/__init__.py b/tests/plugin/plugins/sub_plugin/__init__.py index 215971b..649b399 100644 --- a/tests/plugin/plugins/sub_plugin/__init__.py +++ b/tests/plugin/plugins/sub_plugin/__init__.py @@ -5,7 +5,10 @@ from nonebot_plugin_localstore import ( get_plugin_data_dir, get_plugin_cache_dir, + get_plugin_data_file, + get_plugin_cache_file, get_plugin_config_dir, + get_plugin_config_file, ) sub_plugin_cmd = on_command("sub_plugin") @@ -24,3 +27,21 @@ async def plugin_handle(args: Message = CommandArg()): elif type_ == "data": data_dir = get_plugin_data_dir() await sub_plugin_cmd.finish(f"{data_dir}") + + +sub_plugin_file_cmd = on_command("sub_plugin_file") + + +@sub_plugin_file_cmd.handle() +async def sub_plugin_file_handle(args: Message = CommandArg()): + type_, filename = args.extract_plain_text().split() + + if type_ == "cache": + cache_file = get_plugin_cache_file(filename) + await sub_plugin_file_cmd.finish(f"{cache_file}") + elif type_ == "config": + config_file = get_plugin_config_file(filename) + await sub_plugin_file_cmd.finish(f"{config_file}") + elif type_ == "data": + data_file = get_plugin_data_file(filename) + await sub_plugin_file_cmd.finish(f"{data_file}") diff --git a/tests/test_get_plugin_file.py b/tests/test_get_plugin_file.py new file mode 100644 index 0000000..1249f8d --- /dev/null +++ b/tests/test_get_plugin_file.py @@ -0,0 +1,85 @@ +from pathlib import Path + +from nonebug import App + +from tests.utils import make_fake_event, make_fake_message + + +async def test_plugin_file(app: App, tmp_path: Path): + """获取到插件的缓存文件、配置文件和数据文件""" + from tests.plugin import plugin_file_cmd + + async with app.test_matcher(plugin_file_cmd) as ctx: + bot = ctx.create_bot() + message = make_fake_message()("/plugin_file cache cache_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "cache" / "plugin" / "cache_file"), + True, + ) + ctx.should_finished(plugin_file_cmd) + + message = make_fake_message()("/plugin_file config config_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "config" / "plugin" / "config_file"), + True, + ) + ctx.should_finished(plugin_file_cmd) + + message = make_fake_message()("/plugin_file data data_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "data" / "plugin" / "data_file"), + True, + ) + ctx.should_finished(plugin_file_cmd) + + +async def test_sub_plugin_file(app: App, tmp_path: Path): + """获取到子插件的缓存文件、配置文件和数据文件""" + from tests.plugin.plugins.sub_plugin import sub_plugin_file_cmd + + async with app.test_matcher(sub_plugin_file_cmd) as ctx: + bot = ctx.create_bot() + message = make_fake_message()("/sub_plugin_file cache cache_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "cache" / "plugin" / "sub_plugin" / "cache_file"), + True, + ) + ctx.should_finished(sub_plugin_file_cmd) + + message = make_fake_message()("/sub_plugin_file config config_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "config" / "plugin" / "sub_plugin" / "config_file"), + True, + ) + ctx.should_finished(sub_plugin_file_cmd) + + message = make_fake_message()("/sub_plugin_file data data_file") + event = make_fake_event(_message=message)() + + ctx.receive_event(bot, event) + ctx.should_call_send( + event, + str(tmp_path / "data" / "plugin" / "sub_plugin" / "data_file"), + True, + ) + ctx.should_finished(sub_plugin_file_cmd) From 13048795321e1d2091d5cbe082bf7f8664be1ddc Mon Sep 17 00:00:00 2001 From: uy_sun Date: Fri, 2 Aug 2024 02:02:22 +0800 Subject: [PATCH 5/7] =?UTF-8?q?:zap:=20=E7=9B=B4=E6=8E=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20module=5Fname=20=E5=88=A4=E6=96=AD=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=AF=E6=8F=92=E4=BB=B6=E5=86=85=E9=83=A8=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_localstore/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nonebot_plugin_localstore/__init__.py b/nonebot_plugin_localstore/__init__.py index 87ecec4..17b40f4 100644 --- a/nonebot_plugin_localstore/__init__.py +++ b/nonebot_plugin_localstore/__init__.py @@ -106,6 +106,9 @@ def _get_caller_plugin() -> Optional[Plugin]: return None # skip nonebot_plugin_localstore it self + if module_name.split(".", maxsplit=1)[0] == "nonebot_plugin_localstore": + continue + plugin = get_plugin_by_module_name(module_name) if plugin and plugin.id_ != "nonebot_plugin_localstore": return plugin From fc3f8e1557224607aa0e166ec0e0412ba2cc2ff3 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sat, 3 Aug 2024 04:30:49 +0000 Subject: [PATCH 6/7] :white_check_mark: update test --- .github/actions/setup-python/action.yml | 1 - .github/workflows/codecov.yml | 12 +- poetry.lock | 132 ++++++++------------ pyproject.toml | 11 +- tests/__init__.py | 0 tests/conftest.py | 27 ++-- tests/plugin/__init__.py | 44 +------ tests/plugin/plugins/sub_plugin/__init__.py | 43 +------ tests/test_get_plugin_dir.py | 95 +++----------- tests/test_get_plugin_file.py | 86 ++----------- 10 files changed, 112 insertions(+), 339 deletions(-) delete mode 100644 tests/__init__.py diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml index 7accf10..18afd51 100644 --- a/.github/actions/setup-python/action.yml +++ b/.github/actions/setup-python/action.yml @@ -17,7 +17,6 @@ runs: - uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} - architecture: "x64" cache: "poetry" - run: poetry install diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 3288444..d70d4c9 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -25,22 +25,14 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry - - name: Setup Python environment - uses: actions/setup-python@v5 + uses: ./.github/actions/setup-python with: python-version: ${{ matrix.python-version }} - cache: 'poetry' - - - name: Install dependencies - run: | - poetry install - name: Run Pytest run: | - poetry run pytest --cov=./nonebot_plugin_localstore --cov-report=xml -n auto + poetry run pytest -n auto --cov-append --cov-report xml - name: Upload coverage report uses: codecov/codecov-action@v4 diff --git a/poetry.lock b/poetry.lock index e1047ec..7b069ea 100644 --- a/poetry.lock +++ b/poetry.lock @@ -44,33 +44,33 @@ requests = ">=2.21,<3.0" [[package]] name = "black" -version = "24.4.2" +version = "24.8.0" description = "The uncompromising code formatter." optional = false python-versions = ">=3.8" files = [ - {file = "black-24.4.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce"}, - {file = "black-24.4.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021"}, - {file = "black-24.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063"}, - {file = "black-24.4.2-cp310-cp310-win_amd64.whl", hash = "sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96"}, - {file = "black-24.4.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474"}, - {file = "black-24.4.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c"}, - {file = "black-24.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb"}, - {file = "black-24.4.2-cp311-cp311-win_amd64.whl", hash = "sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1"}, - {file = "black-24.4.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d"}, - {file = "black-24.4.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04"}, - {file = "black-24.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc"}, - {file = "black-24.4.2-cp312-cp312-win_amd64.whl", hash = "sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0"}, - {file = "black-24.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7"}, - {file = "black-24.4.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94"}, - {file = "black-24.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8"}, - {file = "black-24.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c"}, - {file = "black-24.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1"}, - {file = "black-24.4.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741"}, - {file = "black-24.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e"}, - {file = "black-24.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7"}, - {file = "black-24.4.2-py3-none-any.whl", hash = "sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c"}, - {file = "black-24.4.2.tar.gz", hash = "sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d"}, + {file = "black-24.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6"}, + {file = "black-24.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb"}, + {file = "black-24.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42"}, + {file = "black-24.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a"}, + {file = "black-24.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1"}, + {file = "black-24.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af"}, + {file = "black-24.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4"}, + {file = "black-24.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af"}, + {file = "black-24.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368"}, + {file = "black-24.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed"}, + {file = "black-24.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018"}, + {file = "black-24.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2"}, + {file = "black-24.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd"}, + {file = "black-24.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2"}, + {file = "black-24.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e"}, + {file = "black-24.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920"}, + {file = "black-24.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c"}, + {file = "black-24.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e"}, + {file = "black-24.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47"}, + {file = "black-24.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb"}, + {file = "black-24.8.0-py3-none-any.whl", hash = "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed"}, + {file = "black-24.8.0.tar.gz", hash = "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f"}, ] [package.dependencies] @@ -860,24 +860,6 @@ tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] -[[package]] -name = "pytest-asyncio" -version = "0.23.8" -description = "Pytest support for asyncio" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pytest_asyncio-0.23.8-py3-none-any.whl", hash = "sha256:50265d892689a5faefb84df80819d1ecef566eb3549cf915dfb33569359d1ce2"}, - {file = "pytest_asyncio-0.23.8.tar.gz", hash = "sha256:759b10b33a6dc61cce40a8bd5205e302978bbbcc00e279a8b61d9a6a3c82e4d3"}, -] - -[package.dependencies] -pytest = ">=7.0.0,<9" - -[package.extras] -docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] -testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] - [[package]] name = "pytest-cov" version = "5.0.0" @@ -896,23 +878,6 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] -[[package]] -name = "pytest-mock" -version = "3.14.0" -description = "Thin-wrapper around the mock package for easier use with pytest" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"}, - {file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"}, -] - -[package.dependencies] -pytest = ">=6.2.5" - -[package.extras] -dev = ["pre-commit", "pytest-asyncio", "tox"] - [[package]] name = "pytest-xdist" version = "3.6.1" @@ -959,6 +924,7 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -966,8 +932,16 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -984,6 +958,7 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -991,6 +966,7 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -1019,29 +995,29 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.5.5" +version = "0.5.6" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.5.5-py3-none-linux_armv6l.whl", hash = "sha256:605d589ec35d1da9213a9d4d7e7a9c761d90bba78fc8790d1c5e65026c1b9eaf"}, - {file = "ruff-0.5.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:00817603822a3e42b80f7c3298c8269e09f889ee94640cd1fc7f9329788d7bf8"}, - {file = "ruff-0.5.5-py3-none-macosx_11_0_arm64.whl", hash = "sha256:187a60f555e9f865a2ff2c6984b9afeffa7158ba6e1eab56cb830404c942b0f3"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fe26fc46fa8c6e0ae3f47ddccfbb136253c831c3289bba044befe68f467bfb16"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4ad25dd9c5faac95c8e9efb13e15803cd8bbf7f4600645a60ffe17c73f60779b"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f70737c157d7edf749bcb952d13854e8f745cec695a01bdc6e29c29c288fc36e"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:cfd7de17cef6ab559e9f5ab859f0d3296393bc78f69030967ca4d87a541b97a0"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a09b43e02f76ac0145f86a08e045e2ea452066f7ba064fd6b0cdccb486f7c3e7"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d0b856cb19c60cd40198be5d8d4b556228e3dcd545b4f423d1ad812bfdca5884"}, - {file = "ruff-0.5.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3687d002f911e8a5faf977e619a034d159a8373514a587249cc00f211c67a091"}, - {file = "ruff-0.5.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:ac9dc814e510436e30d0ba535f435a7f3dc97f895f844f5b3f347ec8c228a523"}, - {file = "ruff-0.5.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:af9bdf6c389b5add40d89b201425b531e0a5cceb3cfdcc69f04d3d531c6be74f"}, - {file = "ruff-0.5.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d40a8533ed545390ef8315b8e25c4bb85739b90bd0f3fe1280a29ae364cc55d8"}, - {file = "ruff-0.5.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:cab904683bf9e2ecbbe9ff235bfe056f0eba754d0168ad5407832928d579e7ab"}, - {file = "ruff-0.5.5-py3-none-win32.whl", hash = "sha256:696f18463b47a94575db635ebb4c178188645636f05e934fdf361b74edf1bb2d"}, - {file = "ruff-0.5.5-py3-none-win_amd64.whl", hash = "sha256:50f36d77f52d4c9c2f1361ccbfbd09099a1b2ea5d2b2222c586ab08885cf3445"}, - {file = "ruff-0.5.5-py3-none-win_arm64.whl", hash = "sha256:3191317d967af701f1b73a31ed5788795936e423b7acce82a2b63e26eb3e89d6"}, - {file = "ruff-0.5.5.tar.gz", hash = "sha256:cc5516bdb4858d972fbc31d246bdb390eab8df1a26e2353be2dbc0c2d7f5421a"}, + {file = "ruff-0.5.6-py3-none-linux_armv6l.whl", hash = "sha256:a0ef5930799a05522985b9cec8290b185952f3fcd86c1772c3bdbd732667fdcd"}, + {file = "ruff-0.5.6-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b652dc14f6ef5d1552821e006f747802cc32d98d5509349e168f6bf0ee9f8f42"}, + {file = "ruff-0.5.6-py3-none-macosx_11_0_arm64.whl", hash = "sha256:80521b88d26a45e871f31e4b88938fd87db7011bb961d8afd2664982dfc3641a"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d9bc8f328a9f1309ae80e4d392836e7dbc77303b38ed4a7112699e63d3b066ab"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4d394940f61f7720ad371ddedf14722ee1d6250fd8d020f5ea5a86e7be217daf"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:111a99cdb02f69ddb2571e2756e017a1496c2c3a2aeefe7b988ddab38b416d36"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:e395daba77a79f6dc0d07311f94cc0560375ca20c06f354c7c99af3bf4560c5d"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c476acb43c3c51e3c614a2e878ee1589655fa02dab19fe2db0423a06d6a5b1b6"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e2ff8003f5252fd68425fd53d27c1f08b201d7ed714bb31a55c9ac1d4c13e2eb"}, + {file = "ruff-0.5.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c94e084ba3eaa80c2172918c2ca2eb2230c3f15925f4ed8b6297260c6ef179ad"}, + {file = "ruff-0.5.6-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:1f77c1c3aa0669fb230b06fb24ffa3e879391a3ba3f15e3d633a752da5a3e670"}, + {file = "ruff-0.5.6-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:f908148c93c02873210a52cad75a6eda856b2cbb72250370ce3afef6fb99b1ed"}, + {file = "ruff-0.5.6-py3-none-musllinux_1_2_i686.whl", hash = "sha256:563a7ae61ad284187d3071d9041c08019975693ff655438d8d4be26e492760bd"}, + {file = "ruff-0.5.6-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:94fe60869bfbf0521e04fd62b74cbca21cbc5beb67cbb75ab33fe8c174f54414"}, + {file = "ruff-0.5.6-py3-none-win32.whl", hash = "sha256:e6a584c1de6f8591c2570e171cc7ce482bb983d49c70ddf014393cd39e9dfaed"}, + {file = "ruff-0.5.6-py3-none-win_amd64.whl", hash = "sha256:d7fe7dccb1a89dc66785d7aa0ac283b2269712d8ed19c63af908fdccca5ccc1a"}, + {file = "ruff-0.5.6-py3-none-win_arm64.whl", hash = "sha256:57c6c0dd997b31b536bff49b9eee5ed3194d60605a4427f735eeb1f9c1b8d264"}, + {file = "ruff-0.5.6.tar.gz", hash = "sha256:07c9e3c2a8e1fe377dd460371c3462671a728c981c3205a5217291422209f642"}, ] [[package]] @@ -1234,4 +1210,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "a6dfbd87181d1fb0038db1f78a5377a5954484209bce112b0aa5a8537c616bae" +content-hash = "f58d7e814923cd4e69c090784c4507680fe80a9d95c39729a0287d6b5f8eb322" diff --git a/pyproject.toml b/pyproject.toml index 68ea899..e70ca9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,17 +20,18 @@ pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1" ruff = "^0.5.0" isort = "^5.10.1" black = "^24.0.0" +nonebug = "^0.3.7" nonemoji = "^0.1.2" pre-commit = "^3.5.0" -nonebug = "^0.3.7" -pytest-asyncio = "^0.23.8" pytest-cov = "^5.0.0" pytest-xdist = "^3.6.1" -pytest-mock = "^3.14.0" [tool.poetry.plugins.nb_scripts] localstore = "nonebot_plugin_localstore.script:main" +[tool.pytest.ini_options] +addopts = "--cov=./nonebot_plugin_localstore --cov-report=term-missing" + [tool.black] line-length = 88 target-version = ["py39", "py310", "py311", "py312"] @@ -92,7 +93,3 @@ disableBytesTypePromotions = true [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" - -[tool.pytest.ini_options] -addopts = ["--import-mode=importlib"] -asyncio_mode = "auto" diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/conftest.py b/tests/conftest.py index bcc3592..81eac96 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,27 +2,26 @@ import pytest import nonebot -from nonebug.app import App -from pytest_mock import MockerFixture from nonebug import NONEBOT_INIT_KWARGS def pytest_configure(config: pytest.Config) -> None: - config.stash[NONEBOT_INIT_KWARGS] = { - "driver": "~none", - } + config.stash[NONEBOT_INIT_KWARGS] = {"driver": "~none"} @pytest.fixture(scope="session") -def _load_plugin(nonebug_init: None): - nonebot.load_plugin("tests.plugin") +def tmp_path(tmp_path_factory: pytest.TempPathFactory) -> Path: + return tmp_path_factory.mktemp("nonebot_plugin_localstore") -@pytest.fixture -def app(_load_plugin: None, tmp_path: Path, mocker: MockerFixture): - # 插件数据目录 - mocker.patch("nonebot_plugin_localstore.BASE_DATA_DIR", tmp_path / "data") - mocker.patch("nonebot_plugin_localstore.BASE_CACHE_DIR", tmp_path / "cache") - mocker.patch("nonebot_plugin_localstore.BASE_CONFIG_DIR", tmp_path / "config") +@pytest.fixture(scope="session", autouse=True) +def _load_plugin(nonebug_init: None, tmp_path: Path): + nonebot.load_plugin("nonebot_plugin_localstore") - return App() + with pytest.MonkeyPatch.context() as m: + m.setattr("nonebot_plugin_localstore.BASE_DATA_DIR", tmp_path / "data") + m.setattr("nonebot_plugin_localstore.BASE_CACHE_DIR", tmp_path / "cache") + m.setattr("nonebot_plugin_localstore.BASE_CONFIG_DIR", tmp_path / "config") + + nonebot.load_plugin("tests.plugin") + yield diff --git a/tests/plugin/__init__.py b/tests/plugin/__init__.py index 95f4071..38d7569 100644 --- a/tests/plugin/__init__.py +++ b/tests/plugin/__init__.py @@ -1,11 +1,7 @@ from pathlib import Path import nonebot -from nonebot.adapters import Message -from nonebot.params import CommandArg -from nonebot import require, on_command -require("nonebot_plugin_localstore") from nonebot_plugin_localstore import ( get_plugin_data_dir, get_plugin_cache_dir, @@ -15,41 +11,13 @@ get_plugin_config_file, ) -plugin_cmd = on_command("plugin") - - -@plugin_cmd.handle() -async def plugin_handle(args: Message = CommandArg()): - type_ = args.extract_plain_text() - - if type_ == "cache": - cache_dir = get_plugin_cache_dir() - await plugin_cmd.finish(f"{cache_dir}") - elif type_ == "config": - config_dir = get_plugin_config_dir() - await plugin_cmd.finish(f"{config_dir}") - elif type_ == "data": - data_dir = get_plugin_data_dir() - await plugin_cmd.finish(f"{data_dir}") - - -plugin_file_cmd = on_command("plugin_file") - - -@plugin_file_cmd.handle() -async def plugin_file_handle(args: Message = CommandArg()): - type_, filename = args.extract_plain_text().split() - - if type_ == "cache": - cache_file = get_plugin_cache_file(filename) - await plugin_file_cmd.finish(f"{cache_file}") - elif type_ == "config": - config_file = get_plugin_config_file(filename) - await plugin_file_cmd.finish(f"{config_file}") - elif type_ == "data": - data_file = get_plugin_data_file(filename) - await plugin_file_cmd.finish(f"{data_file}") +data_dir = get_plugin_data_dir() +cache_dir = get_plugin_cache_dir() +config_dir = get_plugin_config_dir() +data_file = get_plugin_data_file("data_file") +cache_file = get_plugin_cache_file("cache_file") +config_file = get_plugin_config_file("config_file") _sub_plugins = set() _sub_plugins |= nonebot.load_plugins(str((Path(__file__).parent / "plugins").resolve())) diff --git a/tests/plugin/plugins/sub_plugin/__init__.py b/tests/plugin/plugins/sub_plugin/__init__.py index 649b399..10a1c00 100644 --- a/tests/plugin/plugins/sub_plugin/__init__.py +++ b/tests/plugin/plugins/sub_plugin/__init__.py @@ -1,7 +1,3 @@ -from nonebot import on_command -from nonebot.adapters import Message -from nonebot.params import CommandArg - from nonebot_plugin_localstore import ( get_plugin_data_dir, get_plugin_cache_dir, @@ -11,37 +7,10 @@ get_plugin_config_file, ) -sub_plugin_cmd = on_command("sub_plugin") - - -@sub_plugin_cmd.handle() -async def plugin_handle(args: Message = CommandArg()): - type_ = args.extract_plain_text() - - if type_ == "cache": - cache_dir = get_plugin_cache_dir() - await sub_plugin_cmd.finish(f"{cache_dir}") - elif type_ == "config": - config_dir = get_plugin_config_dir() - await sub_plugin_cmd.finish(f"{config_dir}") - elif type_ == "data": - data_dir = get_plugin_data_dir() - await sub_plugin_cmd.finish(f"{data_dir}") - - -sub_plugin_file_cmd = on_command("sub_plugin_file") - - -@sub_plugin_file_cmd.handle() -async def sub_plugin_file_handle(args: Message = CommandArg()): - type_, filename = args.extract_plain_text().split() +data_dir = get_plugin_data_dir() +cache_dir = get_plugin_cache_dir() +config_dir = get_plugin_config_dir() - if type_ == "cache": - cache_file = get_plugin_cache_file(filename) - await sub_plugin_file_cmd.finish(f"{cache_file}") - elif type_ == "config": - config_file = get_plugin_config_file(filename) - await sub_plugin_file_cmd.finish(f"{config_file}") - elif type_ == "data": - data_file = get_plugin_data_file(filename) - await sub_plugin_file_cmd.finish(f"{data_file}") +data_file = get_plugin_data_file("data_file") +cache_file = get_plugin_cache_file("cache_file") +config_file = get_plugin_config_file("config_file") diff --git a/tests/test_get_plugin_dir.py b/tests/test_get_plugin_dir.py index 8729151..8b7bbbe 100644 --- a/tests/test_get_plugin_dir.py +++ b/tests/test_get_plugin_dir.py @@ -1,85 +1,24 @@ from pathlib import Path -from nonebug import App -from tests.utils import make_fake_event, make_fake_message +def test_plugin_dir(tmp_path: Path): + from tests.plugin import data_dir, cache_dir, config_dir + assert data_dir == tmp_path / "data" / "plugin" + assert data_dir.is_dir() + assert cache_dir == tmp_path / "cache" / "plugin" + assert cache_dir.is_dir() + assert config_dir == tmp_path / "config" / "plugin" + assert config_dir.is_dir() -async def test_plugin_dir(app: App, tmp_path: Path): - """获取到插件的缓存目录、配置目录和数据目录""" - from tests.plugin import plugin_cmd - async with app.test_matcher(plugin_cmd) as ctx: - bot = ctx.create_bot() - message = make_fake_message()("/plugin cache") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "cache" / "plugin"), - True, - ) - ctx.should_finished(plugin_cmd) - - message = make_fake_message()("/plugin config") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "config" / "plugin"), - True, - ) - ctx.should_finished(plugin_cmd) - - message = make_fake_message()("/plugin data") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "data" / "plugin"), - True, - ) - ctx.should_finished(plugin_cmd) - - -async def test_sub_plugin_dir(app: App, tmp_path: Path): +def test_sub_plugin_dir(tmp_path: Path): """获取到子插件的缓存目录、配置目录和数据目录""" - from tests.plugin.plugins.sub_plugin import sub_plugin_cmd - - async with app.test_matcher(sub_plugin_cmd) as ctx: - bot = ctx.create_bot() - message = make_fake_message()("/sub_plugin cache") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "cache" / "plugin" / "sub_plugin"), - True, - ) - ctx.should_finished(sub_plugin_cmd) - - message = make_fake_message()("/sub_plugin config") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "config" / "plugin" / "sub_plugin"), - True, - ) - ctx.should_finished(sub_plugin_cmd) - - message = make_fake_message()("/sub_plugin data") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "data" / "plugin" / "sub_plugin"), - True, - ) - ctx.should_finished(sub_plugin_cmd) + from tests.plugin.plugins.sub_plugin import data_dir, cache_dir, config_dir + + assert data_dir == tmp_path / "data" / "plugin" / "sub_plugin" + assert data_dir.is_dir() + assert cache_dir == tmp_path / "cache" / "plugin" / "sub_plugin" + assert cache_dir.is_dir() + assert config_dir == tmp_path / "config" / "plugin" / "sub_plugin" + assert config_dir.is_dir() diff --git a/tests/test_get_plugin_file.py b/tests/test_get_plugin_file.py index 1249f8d..ccf77b6 100644 --- a/tests/test_get_plugin_file.py +++ b/tests/test_get_plugin_file.py @@ -1,85 +1,19 @@ from pathlib import Path -from nonebug import App -from tests.utils import make_fake_event, make_fake_message - - -async def test_plugin_file(app: App, tmp_path: Path): +def test_plugin_file(tmp_path: Path): """获取到插件的缓存文件、配置文件和数据文件""" - from tests.plugin import plugin_file_cmd - - async with app.test_matcher(plugin_file_cmd) as ctx: - bot = ctx.create_bot() - message = make_fake_message()("/plugin_file cache cache_file") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "cache" / "plugin" / "cache_file"), - True, - ) - ctx.should_finished(plugin_file_cmd) - - message = make_fake_message()("/plugin_file config config_file") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "config" / "plugin" / "config_file"), - True, - ) - ctx.should_finished(plugin_file_cmd) + from tests.plugin import data_file, cache_file, config_file - message = make_fake_message()("/plugin_file data data_file") - event = make_fake_event(_message=message)() + assert data_file == tmp_path / "data" / "plugin" / "data_file" + assert cache_file == tmp_path / "cache" / "plugin" / "cache_file" + assert config_file == tmp_path / "config" / "plugin" / "config_file" - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "data" / "plugin" / "data_file"), - True, - ) - ctx.should_finished(plugin_file_cmd) - -async def test_sub_plugin_file(app: App, tmp_path: Path): +def test_sub_plugin_file(tmp_path: Path): """获取到子插件的缓存文件、配置文件和数据文件""" - from tests.plugin.plugins.sub_plugin import sub_plugin_file_cmd - - async with app.test_matcher(sub_plugin_file_cmd) as ctx: - bot = ctx.create_bot() - message = make_fake_message()("/sub_plugin_file cache cache_file") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "cache" / "plugin" / "sub_plugin" / "cache_file"), - True, - ) - ctx.should_finished(sub_plugin_file_cmd) - - message = make_fake_message()("/sub_plugin_file config config_file") - event = make_fake_event(_message=message)() - - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "config" / "plugin" / "sub_plugin" / "config_file"), - True, - ) - ctx.should_finished(sub_plugin_file_cmd) - - message = make_fake_message()("/sub_plugin_file data data_file") - event = make_fake_event(_message=message)() + from tests.plugin.plugins.sub_plugin import data_file, cache_file, config_file - ctx.receive_event(bot, event) - ctx.should_call_send( - event, - str(tmp_path / "data" / "plugin" / "sub_plugin" / "data_file"), - True, - ) - ctx.should_finished(sub_plugin_file_cmd) + assert data_file == tmp_path / "data" / "plugin" / "sub_plugin" / "data_file" + assert cache_file == tmp_path / "cache" / "plugin" / "sub_plugin" / "cache_file" + assert config_file == tmp_path / "config" / "plugin" / "sub_plugin" / "config_file" From d5e21d6c5494f253cfbea546c263bba10746dc3f Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sat, 3 Aug 2024 04:46:44 +0000 Subject: [PATCH 7/7] :white_check_mark: remove unused code --- tests/test_get_plugin_dir.py | 1 - tests/test_get_plugin_file.py | 2 - tests/utils.py | 81 ----------------------------------- 3 files changed, 84 deletions(-) delete mode 100644 tests/utils.py diff --git a/tests/test_get_plugin_dir.py b/tests/test_get_plugin_dir.py index 8b7bbbe..d956fe5 100644 --- a/tests/test_get_plugin_dir.py +++ b/tests/test_get_plugin_dir.py @@ -13,7 +13,6 @@ def test_plugin_dir(tmp_path: Path): def test_sub_plugin_dir(tmp_path: Path): - """获取到子插件的缓存目录、配置目录和数据目录""" from tests.plugin.plugins.sub_plugin import data_dir, cache_dir, config_dir assert data_dir == tmp_path / "data" / "plugin" / "sub_plugin" diff --git a/tests/test_get_plugin_file.py b/tests/test_get_plugin_file.py index ccf77b6..6900fd5 100644 --- a/tests/test_get_plugin_file.py +++ b/tests/test_get_plugin_file.py @@ -2,7 +2,6 @@ def test_plugin_file(tmp_path: Path): - """获取到插件的缓存文件、配置文件和数据文件""" from tests.plugin import data_file, cache_file, config_file assert data_file == tmp_path / "data" / "plugin" / "data_file" @@ -11,7 +10,6 @@ def test_plugin_file(tmp_path: Path): def test_sub_plugin_file(tmp_path: Path): - """获取到子插件的缓存文件、配置文件和数据文件""" from tests.plugin.plugins.sub_plugin import data_file, cache_file, config_file assert data_file == tmp_path / "data" / "plugin" / "sub_plugin" / "data_file" diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index b663e1c..0000000 --- a/tests/utils.py +++ /dev/null @@ -1,81 +0,0 @@ -from typing import TYPE_CHECKING, Optional - -from pydantic import create_model - -if TYPE_CHECKING: - from nonebot.adapters import Event, Message - - -def make_fake_message() -> type["Message"]: - from nonebot.adapters import Message, MessageSegment - - class FakeMessageSegment(MessageSegment): - @classmethod - def get_message_class(cls): - return FakeMessage - - def __str__(self) -> str: - return self.data["text"] if self.type == "text" else f"[fake:{self.type}]" - - @classmethod - def text(cls, text: str): - return cls("text", {"text": text}) - - @classmethod - def image(cls, url: str): - return cls("image", {"url": url}) - - def is_text(self) -> bool: - return self.type == "text" - - class FakeMessage(Message): - @classmethod - def get_segment_class(cls): - return FakeMessageSegment - - @staticmethod - def _construct(msg: str): - yield FakeMessageSegment.text(msg) - - return FakeMessage - - -def make_fake_event( - _type: str = "message", - _name: str = "test", - _description: str = "test", - _user_id: str = "test", - _session_id: str = "test", - _message: Optional["Message"] = None, - _to_me: bool = True, - **fields, -) -> type["Event"]: - from nonebot.adapters import Event - - _Fake = create_model("_Fake", __base__=Event, **fields) - - class FakeEvent(_Fake): - def get_type(self) -> str: - return _type - - def get_event_name(self) -> str: - return _name - - def get_event_description(self) -> str: - return _description - - def get_user_id(self) -> str: - return _user_id - - def get_session_id(self) -> str: - return _session_id - - def get_message(self) -> "Message": - if _message is not None: - return _message - raise NotImplementedError - - def is_tome(self) -> bool: - return _to_me - - return FakeEvent