From 0201d5b31650da3a077315caff26e5bfc9806ac4 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 3 Mar 2023 15:12:25 +0800 Subject: [PATCH] =?UTF-8?q?:arrow=5Fup:=20=E5=8D=87=E7=BA=A7=E8=87=B3=20No?= =?UTF-8?q?neBug=200.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :construction: 第一次尝试 50/82 * 62/82 调整了清除数据库的位置 * :construction: pytest-mock * :construction: fix test_send * :construction: intruduce app request * :construction: close and remove tinydb after each test * :construction: clean ScheduleTimeWeight table * :construction: reload http module to test proxy * :white_check_mark: 合并 main 的代码 * 🚧 在每次测试结束后关闭browser * :technologist: 在mcbbsnews渲染异常时添加logger --------- Co-authored-by: hemengyang Co-authored-by: Azide --- poetry.lock | 221 ++++++++++-------- pyproject.toml | 38 +-- .../nonebot_bison/platform/mcbbsnews.py | 8 +- tests/config/test_config_legacy.py | 7 +- tests/config/test_scheduler_conf.py | 11 +- tests/conftest.py | 88 ++++--- tests/platforms/test_weibo.py | 1 - tests/scheduler/test_scheduler.py | 8 +- tests/test_config_manager_add.py | 5 +- tests/test_get_bot.py | 5 + tests/test_proxy.py | 18 +- tests/test_send.py | 12 +- tests/utils.py | 7 +- 13 files changed, 258 insertions(+), 171 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3ae0553..b0f85f6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -421,63 +421,63 @@ files = [ [[package]] name = "coverage" -version = "7.1.0" +version = "7.2.1" description = "Code coverage measurement for Python" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "coverage-7.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3b946bbcd5a8231383450b195cfb58cb01cbe7f8949f5758566b881df4b33baf"}, - {file = "coverage-7.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ec8e767f13be637d056f7e07e61d089e555f719b387a7070154ad80a0ff31801"}, - {file = "coverage-7.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d4a5a5879a939cb84959d86869132b00176197ca561c664fc21478c1eee60d75"}, - {file = "coverage-7.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b643cb30821e7570c0aaf54feaf0bfb630b79059f85741843e9dc23f33aaca2c"}, - {file = "coverage-7.1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:32df215215f3af2c1617a55dbdfb403b772d463d54d219985ac7cd3bf124cada"}, - {file = "coverage-7.1.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:33d1ae9d4079e05ac4cc1ef9e20c648f5afabf1a92adfaf2ccf509c50b85717f"}, - {file = "coverage-7.1.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:29571503c37f2ef2138a306d23e7270687c0efb9cab4bd8038d609b5c2393a3a"}, - {file = "coverage-7.1.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:63ffd21aa133ff48c4dff7adcc46b7ec8b565491bfc371212122dd999812ea1c"}, - {file = "coverage-7.1.0-cp310-cp310-win32.whl", hash = "sha256:4b14d5e09c656de5038a3f9bfe5228f53439282abcab87317c9f7f1acb280352"}, - {file = "coverage-7.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:8361be1c2c073919500b6601220a6f2f98ea0b6d2fec5014c1d9cfa23dd07038"}, - {file = "coverage-7.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:da9b41d4539eefd408c46725fb76ecba3a50a3367cafb7dea5f250d0653c1040"}, - {file = "coverage-7.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c5b15ed7644ae4bee0ecf74fee95808dcc34ba6ace87e8dfbf5cb0dc20eab45a"}, - {file = "coverage-7.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d12d076582507ea460ea2a89a8c85cb558f83406c8a41dd641d7be9a32e1274f"}, - {file = "coverage-7.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e2617759031dae1bf183c16cef8fcfb3de7617f394c813fa5e8e46e9b82d4222"}, - {file = "coverage-7.1.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c4e4881fa9e9667afcc742f0c244d9364d197490fbc91d12ac3b5de0bf2df146"}, - {file = "coverage-7.1.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:9d58885215094ab4a86a6aef044e42994a2bd76a446dc59b352622655ba6621b"}, - {file = "coverage-7.1.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:ffeeb38ee4a80a30a6877c5c4c359e5498eec095878f1581453202bfacc8fbc2"}, - {file = "coverage-7.1.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3baf5f126f30781b5e93dbefcc8271cb2491647f8283f20ac54d12161dff080e"}, - {file = "coverage-7.1.0-cp311-cp311-win32.whl", hash = "sha256:ded59300d6330be27bc6cf0b74b89ada58069ced87c48eaf9344e5e84b0072f7"}, - {file = "coverage-7.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:6a43c7823cd7427b4ed763aa7fb63901ca8288591323b58c9cd6ec31ad910f3c"}, - {file = "coverage-7.1.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:7a726d742816cb3a8973c8c9a97539c734b3a309345236cd533c4883dda05b8d"}, - {file = "coverage-7.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bc7c85a150501286f8b56bd8ed3aa4093f4b88fb68c0843d21ff9656f0009d6a"}, - {file = "coverage-7.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f5b4198d85a3755d27e64c52f8c95d6333119e49fd001ae5798dac872c95e0f8"}, - {file = "coverage-7.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ddb726cb861c3117a553f940372a495fe1078249ff5f8a5478c0576c7be12050"}, - {file = "coverage-7.1.0-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:51b236e764840a6df0661b67e50697aaa0e7d4124ca95e5058fa3d7cbc240b7c"}, - {file = "coverage-7.1.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:7ee5c9bb51695f80878faaa5598040dd6c9e172ddcf490382e8aedb8ec3fec8d"}, - {file = "coverage-7.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:c31b75ae466c053a98bf26843563b3b3517b8f37da4d47b1c582fdc703112bc3"}, - {file = "coverage-7.1.0-cp37-cp37m-win32.whl", hash = "sha256:3b155caf3760408d1cb903b21e6a97ad4e2bdad43cbc265e3ce0afb8e0057e73"}, - {file = "coverage-7.1.0-cp37-cp37m-win_amd64.whl", hash = "sha256:2a60d6513781e87047c3e630b33b4d1e89f39836dac6e069ffee28c4786715f5"}, - {file = "coverage-7.1.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f2cba5c6db29ce991029b5e4ac51eb36774458f0a3b8d3137241b32d1bb91f06"}, - {file = "coverage-7.1.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:beeb129cacea34490ffd4d6153af70509aa3cda20fdda2ea1a2be870dfec8d52"}, - {file = "coverage-7.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0c45948f613d5d18c9ec5eaa203ce06a653334cf1bd47c783a12d0dd4fd9c851"}, - {file = "coverage-7.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ef382417db92ba23dfb5864a3fc9be27ea4894e86620d342a116b243ade5d35d"}, - {file = "coverage-7.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7c7c0d0827e853315c9bbd43c1162c006dd808dbbe297db7ae66cd17b07830f0"}, - {file = "coverage-7.1.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:e5cdbb5cafcedea04924568d990e20ce7f1945a1dd54b560f879ee2d57226912"}, - {file = "coverage-7.1.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:9817733f0d3ea91bea80de0f79ef971ae94f81ca52f9b66500c6a2fea8e4b4f8"}, - {file = "coverage-7.1.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:218fe982371ac7387304153ecd51205f14e9d731b34fb0568181abaf7b443ba0"}, - {file = "coverage-7.1.0-cp38-cp38-win32.whl", hash = "sha256:04481245ef966fbd24ae9b9e537ce899ae584d521dfbe78f89cad003c38ca2ab"}, - {file = "coverage-7.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:8ae125d1134bf236acba8b83e74c603d1b30e207266121e76484562bc816344c"}, - {file = "coverage-7.1.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2bf1d5f2084c3932b56b962a683074a3692bce7cabd3aa023c987a2a8e7612f6"}, - {file = "coverage-7.1.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:98b85dd86514d889a2e3dd22ab3c18c9d0019e696478391d86708b805f4ea0fa"}, - {file = "coverage-7.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:38da2db80cc505a611938d8624801158e409928b136c8916cd2e203970dde4dc"}, - {file = "coverage-7.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3164d31078fa9efe406e198aecd2a02d32a62fecbdef74f76dad6a46c7e48311"}, - {file = "coverage-7.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db61a79c07331e88b9a9974815c075fbd812bc9dbc4dc44b366b5368a2936063"}, - {file = "coverage-7.1.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:9ccb092c9ede70b2517a57382a601619d20981f56f440eae7e4d7eaafd1d1d09"}, - {file = "coverage-7.1.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:33ff26d0f6cc3ca8de13d14fde1ff8efe1456b53e3f0273e63cc8b3c84a063d8"}, - {file = "coverage-7.1.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:d47dd659a4ee952e90dc56c97d78132573dc5c7b09d61b416a9deef4ebe01a0c"}, - {file = "coverage-7.1.0-cp39-cp39-win32.whl", hash = "sha256:d248cd4a92065a4d4543b8331660121b31c4148dd00a691bfb7a5cdc7483cfa4"}, - {file = "coverage-7.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:7ed681b0f8e8bcbbffa58ba26fcf5dbc8f79e7997595bf071ed5430d8c08d6f3"}, - {file = "coverage-7.1.0-pp37.pp38.pp39-none-any.whl", hash = "sha256:755e89e32376c850f826c425ece2c35a4fc266c081490eb0a841e7c1cb0d3bda"}, - {file = "coverage-7.1.0.tar.gz", hash = "sha256:10188fe543560ec4874f974b5305cd1a8bdcfa885ee00ea3a03733464c4ca265"}, + {file = "coverage-7.2.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:49567ec91fc5e0b15356da07a2feabb421d62f52a9fff4b1ec40e9e19772f5f8"}, + {file = "coverage-7.2.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d2ef6cae70168815ed91388948b5f4fcc69681480a0061114db737f957719f03"}, + {file = "coverage-7.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3004765bca3acd9e015794e5c2f0c9a05587f5e698127ff95e9cfba0d3f29339"}, + {file = "coverage-7.2.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cca7c0b7f5881dfe0291ef09ba7bb1582cb92ab0aeffd8afb00c700bf692415a"}, + {file = "coverage-7.2.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b2167d116309f564af56f9aa5e75ef710ef871c5f9b313a83050035097b56820"}, + {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:cb5f152fb14857cbe7f3e8c9a5d98979c4c66319a33cad6e617f0067c9accdc4"}, + {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:87dc37f16fb5e3a28429e094145bf7c1753e32bb50f662722e378c5851f7fdc6"}, + {file = "coverage-7.2.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:e191a63a05851f8bce77bc875e75457f9b01d42843f8bd7feed2fc26bbe60833"}, + {file = "coverage-7.2.1-cp310-cp310-win32.whl", hash = "sha256:e3ea04b23b114572b98a88c85379e9e9ae031272ba1fb9b532aa934c621626d4"}, + {file = "coverage-7.2.1-cp310-cp310-win_amd64.whl", hash = "sha256:0cf557827be7eca1c38a2480484d706693e7bb1929e129785fe59ec155a59de6"}, + {file = "coverage-7.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:570c21a29493b350f591a4b04c158ce1601e8d18bdcd21db136fbb135d75efa6"}, + {file = "coverage-7.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9e872b082b32065ac2834149dc0adc2a2e6d8203080501e1e3c3c77851b466f9"}, + {file = "coverage-7.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fac6343bae03b176e9b58104a9810df3cdccd5cfed19f99adfa807ffbf43cf9b"}, + {file = "coverage-7.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:abacd0a738e71b20e224861bc87e819ef46fedba2fb01bc1af83dfd122e9c319"}, + {file = "coverage-7.2.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d9256d4c60c4bbfec92721b51579c50f9e5062c21c12bec56b55292464873508"}, + {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:80559eaf6c15ce3da10edb7977a1548b393db36cbc6cf417633eca05d84dd1ed"}, + {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:0bd7e628f6c3ec4e7d2d24ec0e50aae4e5ae95ea644e849d92ae4805650b4c4e"}, + {file = "coverage-7.2.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:09643fb0df8e29f7417adc3f40aaf379d071ee8f0350ab290517c7004f05360b"}, + {file = "coverage-7.2.1-cp311-cp311-win32.whl", hash = "sha256:1b7fb13850ecb29b62a447ac3516c777b0e7a09ecb0f4bb6718a8654c87dfc80"}, + {file = "coverage-7.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:617a94ada56bbfe547aa8d1b1a2b8299e2ec1ba14aac1d4b26a9f7d6158e1273"}, + {file = "coverage-7.2.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8649371570551d2fd7dee22cfbf0b61f1747cdfb2b7587bb551e4beaaa44cb97"}, + {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d2b9b5e70a21474c105a133ba227c61bc95f2ac3b66861143ce39a5ea4b3f84"}, + {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ae82c988954722fa07ec5045c57b6d55bc1a0890defb57cf4a712ced65b26ddd"}, + {file = "coverage-7.2.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:861cc85dfbf55a7a768443d90a07e0ac5207704a9f97a8eb753292a7fcbdfcfc"}, + {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:0339dc3237c0d31c3b574f19c57985fcbe494280153bbcad33f2cdf469f4ac3e"}, + {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:5928b85416a388dd557ddc006425b0c37e8468bd1c3dc118c1a3de42f59e2a54"}, + {file = "coverage-7.2.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:8d3843ca645f62c426c3d272902b9de90558e9886f15ddf5efe757b12dd376f5"}, + {file = "coverage-7.2.1-cp37-cp37m-win32.whl", hash = "sha256:6a034480e9ebd4e83d1aa0453fd78986414b5d237aea89a8fdc35d330aa13bae"}, + {file = "coverage-7.2.1-cp37-cp37m-win_amd64.whl", hash = "sha256:6fce673f79a0e017a4dc35e18dc7bb90bf6d307c67a11ad5e61ca8d42b87cbff"}, + {file = "coverage-7.2.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7f099da6958ddfa2ed84bddea7515cb248583292e16bb9231d151cd528eab657"}, + {file = "coverage-7.2.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:97a3189e019d27e914ecf5c5247ea9f13261d22c3bb0cfcfd2a9b179bb36f8b1"}, + {file = "coverage-7.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a81dbcf6c6c877986083d00b834ac1e84b375220207a059ad45d12f6e518a4e3"}, + {file = "coverage-7.2.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:78d2c3dde4c0b9be4b02067185136b7ee4681978228ad5ec1278fa74f5ca3e99"}, + {file = "coverage-7.2.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a209d512d157379cc9ab697cbdbb4cfd18daa3e7eebaa84c3d20b6af0037384"}, + {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:f3d07edb912a978915576a776756069dede66d012baa503022d3a0adba1b6afa"}, + {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:8dca3c1706670297851bca1acff9618455122246bdae623be31eca744ade05ec"}, + {file = "coverage-7.2.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b1991a6d64231a3e5bbe3099fb0dd7c9aeaa4275ad0e0aeff4cb9ef885c62ba2"}, + {file = "coverage-7.2.1-cp38-cp38-win32.whl", hash = "sha256:22c308bc508372576ffa3d2dbc4824bb70d28eeb4fcd79d4d1aed663a06630d0"}, + {file = "coverage-7.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:b0c0d46de5dd97f6c2d1b560bf0fcf0215658097b604f1840365296302a9d1fb"}, + {file = "coverage-7.2.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4dd34a935de268a133e4741827ae951283a28c0125ddcdbcbba41c4b98f2dfef"}, + {file = "coverage-7.2.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:0f8318ed0f3c376cfad8d3520f496946977abde080439d6689d7799791457454"}, + {file = "coverage-7.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:834c2172edff5a08d78e2f53cf5e7164aacabeb66b369f76e7bb367ca4e2d993"}, + {file = "coverage-7.2.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e4d70c853f0546855f027890b77854508bdb4d6a81242a9d804482e667fff6e6"}, + {file = "coverage-7.2.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8a6450da4c7afc4534305b2b7d8650131e130610cea448ff240b6ab73d7eab63"}, + {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:99f4dd81b2bb8fc67c3da68b1f5ee1650aca06faa585cbc6818dbf67893c6d58"}, + {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:bdd3f2f285ddcf2e75174248b2406189261a79e7fedee2ceeadc76219b6faa0e"}, + {file = "coverage-7.2.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:f29351393eb05e6326f044a7b45ed8e38cb4dcc38570d12791f271399dc41431"}, + {file = "coverage-7.2.1-cp39-cp39-win32.whl", hash = "sha256:e2b50ebc2b6121edf352336d503357321b9d8738bb7a72d06fc56153fd3f4cd8"}, + {file = "coverage-7.2.1-cp39-cp39-win_amd64.whl", hash = "sha256:bd5a12239c0006252244f94863f1c518ac256160cd316ea5c47fb1a11b25889a"}, + {file = "coverage-7.2.1-pp37.pp38.pp39-none-any.whl", hash = "sha256:436313d129db7cf5b4ac355dd2bd3f7c7e5294af077b090b85de75f8458b8616"}, + {file = "coverage-7.2.1.tar.gz", hash = "sha256:c77f2a9093ccf329dd523a9b2b3c854c20d2a3d968b6def3b820272ca6732242"}, ] [package.dependencies] @@ -905,14 +905,14 @@ tomli = {version = "*", markers = "python_version > \"3.6\" and python_version < [[package]] name = "ipython" -version = "8.10.0" +version = "8.11.0" description = "IPython: Productive Interactive Computing" category = "dev" optional = false python-versions = ">=3.8" files = [ - {file = "ipython-8.10.0-py3-none-any.whl", hash = "sha256:b38c31e8fc7eff642fc7c597061fff462537cf2314e3225a19c906b7b0d8a345"}, - {file = "ipython-8.10.0.tar.gz", hash = "sha256:b13a1d6c1f5818bd388db53b7107d17454129a70de2b87481d555daede5eb49e"}, + {file = "ipython-8.11.0-py3-none-any.whl", hash = "sha256:5b54478e459155a326bf5f42ee4f29df76258c0279c36f21d71ddb560f88b156"}, + {file = "ipython-8.11.0.tar.gz", hash = "sha256:735cede4099dbc903ee540307b9171fbfef4aa75cfcacc5a273b2cda2f02be04"}, ] [package.dependencies] @@ -924,7 +924,7 @@ jedi = ">=0.16" matplotlib-inline = "*" pexpect = {version = ">4.3", markers = "sys_platform != \"win32\""} pickleshare = "*" -prompt-toolkit = ">=3.0.30,<3.1.0" +prompt-toolkit = ">=3.0.30,<3.0.37 || >3.0.37,<3.1.0" pygments = ">=2.4.0" stack-data = "*" traitlets = ">=5" @@ -1381,20 +1381,20 @@ nonebot2 = ">=2.0.0-rc.1,<3.0.0" [[package]] name = "nonebot-plugin-datastore" -version = "0.5.8" +version = "0.5.10" description = "适用于 Nonebot2 的数据存储插件" category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "nonebot_plugin_datastore-0.5.8-py3-none-any.whl", hash = "sha256:4a5635d2b5e6fc9646602b165f18661d4cb8b53e465b76fa30ed96a516cf4bf9"}, - {file = "nonebot_plugin_datastore-0.5.8.tar.gz", hash = "sha256:f71c1c185012c0ba0f2a3b3fd13f5814c84f8a08aaf81691ec550862d1d118d7"}, + {file = "nonebot_plugin_datastore-0.5.10-py3-none-any.whl", hash = "sha256:123ca84efc5eec1fc3d5b34f36ba255c2e2ae11f860be95ee3191982a7e13377"}, + {file = "nonebot_plugin_datastore-0.5.10.tar.gz", hash = "sha256:3b40a53dd4c7a84d967031f782128b50353c4364febfadaf81cf152fc5f82353"}, ] [package.dependencies] aiosqlite = ">=0.17,<0.19" alembic = ">=1.9.1,<2.0.0" -nonebot-plugin-localstore = ">=0.2.0,<0.3.0 || >0.3.0,<0.4.0" +nonebot-plugin-localstore = ">=0.2.0,<0.3.0 || >0.3.0,<0.4.0 || >0.4.0,<0.5.0" nonebot2 = {version = ">=2.0.0-rc.1,<3.0.0", extras = ["httpx"]} sqlmodel = ">=0.0.8,<0.1.0" @@ -1425,18 +1425,19 @@ python-markdown-math = ">=0.8" [[package]] name = "nonebot-plugin-localstore" -version = "0.3.1" +version = "0.4.1" description = "Local Storage Support for NoneBot2" category = "main" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "nonebot_plugin_localstore-0.3.1-py3-none-any.whl", hash = "sha256:5a03e731a354105741852121fa6fa30508ad9c1b93eb9f42f8ba02924128a985"}, - {file = "nonebot_plugin_localstore-0.3.1.tar.gz", hash = "sha256:fa332f5b887d8a77aaffc48a30e8f57a8c668bb761b678822f64075eec3dfa4e"}, + {file = "nonebot_plugin_localstore-0.4.1-py3-none-any.whl", hash = "sha256:dea442fcf8baa5898c15ccea761703cdde46e6fc6bb1c886261b0ab793db8193"}, + {file = "nonebot_plugin_localstore-0.4.1.tar.gz", hash = "sha256:9b6dcb98f6a4e48c5c80b2319acc2e1c424462261a210491d437f5b96abb5d67"}, ] [package.dependencies] nonebot2 = ">=2.0.0-rc.1,<3.0.0" +typing-extensions = ">=4.0.0" [[package]] name = "nonebot2" @@ -1471,22 +1472,26 @@ websockets = ["websockets (>=10.0,<11.0)"] [[package]] name = "nonebug" -version = "0.2.3" +version = "0.3.1" description = "nonebot2 test framework" category = "dev" optional = false -python-versions = ">=3.8,<4.0" -files = [ - {file = "nonebug-0.2.3-py3-none-any.whl", hash = "sha256:5c83bd885899b2857323fa19eff6bbc3f160729453b2f289d8305a99b7b95fc9"}, - {file = "nonebug-0.2.3.tar.gz", hash = "sha256:3e59757b32b6b96cd8c36c4c9fd6050e611b1ffad058ec5fa82cba3f86495c61"}, -] +python-versions = "^3.8" +files = [] +develop = false [package.dependencies] -asgiref = ">=3.4.0,<4.0.0" -async-asgi-testclient = ">=1.4.8,<2.0.0" -nonebot2 = ">=2.0.0-beta.1,<3.0.0" -pytest = ">=7.0.0,<8.0.0" -typing-extensions = ">=4.0.0,<5.0.0" +asgiref = "^3.4.0" +async-asgi-testclient = "^1.4.8" +nonebot2 = "^2.0.0-rc.2" +pytest = "^7.0.0" +typing-extensions = "^4.0.0" + +[package.source] +type = "git" +url = "https://github.com/nonebot/nonebug.git" +reference = "master" +resolved_reference = "026d0765124958739c0abf915db82cc75f0fb55c" [[package]] name = "packaging" @@ -1664,19 +1669,19 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.2.2)", "pytest (>=7.2.1)", "pytes [[package]] name = "playwright" -version = "1.30.0" +version = "1.31.1" description = "A high-level API to automate web browsers" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "playwright-1.30.0-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:2ea5d88880fbfa69f05ab758ddd66310079828d6c5c8efe497485c341d147a4e"}, - {file = "playwright-1.30.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:228e07e1b2ef0790ec6d258897c50b83b0e8055b318fa2d33fcb86a8c5ba3525"}, - {file = "playwright-1.30.0-py3-none-macosx_11_0_universal2.whl", hash = "sha256:115f5d77a21597200428411186ec72e10fed1cc4d7de3e6e705c415b781d344a"}, - {file = "playwright-1.30.0-py3-none-manylinux1_x86_64.whl", hash = "sha256:24bb8fe1d7ae60ec971668812c0c6c21b2b12d320ff24da59cbb544a6a15a53c"}, - {file = "playwright-1.30.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:62032a1da59524a7f8d8cb4ed998cf793310b67693d3df94d00ceb13b5a9eced"}, - {file = "playwright-1.30.0-py3-none-win32.whl", hash = "sha256:07249da8375fa7d52cbcdbfc36f5773f91fa8305aa340215db173101d289e210"}, - {file = "playwright-1.30.0-py3-none-win_amd64.whl", hash = "sha256:198c1d816e802c4c9bc048232ec344f4bdfe3229e73a3a28a8eac33c46dab201"}, + {file = "playwright-1.31.1-py3-none-macosx_10_13_x86_64.whl", hash = "sha256:225ff39ff29219caab242a562e6a5efa486d4659ac10d16421ad5904c7f23b25"}, + {file = "playwright-1.31.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:c51029b8837f3533277718ff003a6fc1b512e7879ef4880306c69048345d04ac"}, + {file = "playwright-1.31.1-py3-none-macosx_11_0_universal2.whl", hash = "sha256:d74ee6b7de96ddaf3af91a90d6160beda68b281b1027b8afec46945062c25aec"}, + {file = "playwright-1.31.1-py3-none-manylinux1_x86_64.whl", hash = "sha256:12c73e6a10ba8a1ddac4849a6f06c753e38de60bec6db5f50f7580ade5772d97"}, + {file = "playwright-1.31.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f032c87b918a0b348b15065d5a67693cd70f39861ea65b8c9f0b63c991bf1a75"}, + {file = "playwright-1.31.1-py3-none-win32.whl", hash = "sha256:5a3eefb7bbe5fb90c89b31ac52a6d78dde94cf82d5fbe0a999789a37d414a92f"}, + {file = "playwright-1.31.1-py3-none-win_amd64.whl", hash = "sha256:5cb681c1bfc05e49dfe5299b9bf2f51300e60ed077d47c927c8f056938972565"}, ] [package.dependencies] @@ -1720,14 +1725,14 @@ virtualenv = ">=20.10.0" [[package]] name = "prompt-toolkit" -version = "3.0.36" +version = "3.0.38" description = "Library for building powerful interactive command lines in Python" category = "dev" optional = false -python-versions = ">=3.6.2" +python-versions = ">=3.7.0" files = [ - {file = "prompt_toolkit-3.0.36-py3-none-any.whl", hash = "sha256:aa64ad242a462c5ff0363a7b9cfe696c20d55d9fc60c11fd8e632d064804d305"}, - {file = "prompt_toolkit-3.0.36.tar.gz", hash = "sha256:3e163f254bef5a03b146397d7c1963bd3e2812f0964bb9a24e6ec761fd28db63"}, + {file = "prompt_toolkit-3.0.38-py3-none-any.whl", hash = "sha256:45ea77a2f7c60418850331366c81cf6b5b9cf4c7fd34616f733c5427e6abbb1f"}, + {file = "prompt_toolkit-3.0.38.tar.gz", hash = "sha256:23ac5d50538a9a38c8bde05fecb47d0b403ecd0662857a86f886f798563d5b9b"}, ] [package.dependencies] @@ -1952,15 +1957,33 @@ pytest = ">=4.6" testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] [[package]] -name = "python-dotenv" -version = "0.21.1" -description = "Read key-value pairs from a .env file and set them as environment variables" -category = "main" +name = "pytest-mock" +version = "3.10.0" +description = "Thin-wrapper around the mock package for easier use with pytest" +category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "python-dotenv-0.21.1.tar.gz", hash = "sha256:1c93de8f636cde3ce377292818d0e440b6e45a82f215c3744979151fa8151c49"}, - {file = "python_dotenv-0.21.1-py3-none-any.whl", hash = "sha256:41e12e0318bebc859fcc4d97d4db8d20ad21721a6aa5047dd59f090391cb549a"}, + {file = "pytest-mock-3.10.0.tar.gz", hash = "sha256:fbbdb085ef7c252a326fd8cdcac0aa3b1333d8811f131bdcc701002e1be7ed4f"}, + {file = "pytest_mock-3.10.0-py3-none-any.whl", hash = "sha256:f4c973eeae0282963eb293eb173ce91b091a79c1334455acfac9ddee8a1c784b"}, +] + +[package.dependencies] +pytest = ">=5.0" + +[package.extras] +dev = ["pre-commit", "pytest-asyncio", "tox"] + +[[package]] +name = "python-dotenv" +version = "1.0.0" +description = "Read key-value pairs from a .env file and set them as environment variables" +category = "main" +optional = false +python-versions = ">=3.8" +files = [ + {file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"}, + {file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"}, ] [package.extras] @@ -2151,14 +2174,14 @@ idna2008 = ["idna"] [[package]] name = "setuptools" -version = "67.3.2" +version = "67.4.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "setuptools-67.3.2-py3-none-any.whl", hash = "sha256:bb6d8e508de562768f2027902929f8523932fcd1fb784e6d573d2cafac995a48"}, - {file = "setuptools-67.3.2.tar.gz", hash = "sha256:95f00380ef2ffa41d9bba85d95b27689d923c93dfbafed4aecd7cf988a25e012"}, + {file = "setuptools-67.4.0-py3-none-any.whl", hash = "sha256:f106dee1b506dee5102cc3f3e9e68137bbad6d47b616be7991714b0c62204251"}, + {file = "setuptools-67.4.0.tar.gz", hash = "sha256:e5fd0a713141a4a105412233c63dc4e17ba0090c8e8334594ac790ec97792330"}, ] [package.extras] @@ -2560,14 +2583,14 @@ test = ["Cython (>=0.29.32,<0.30.0)", "aiohttp", "flake8 (>=3.9.2,<3.10.0)", "my [[package]] name = "virtualenv" -version = "20.19.0" +version = "20.20.0" description = "Virtual Python Environment builder" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.19.0-py3-none-any.whl", hash = "sha256:54eb59e7352b573aa04d53f80fc9736ed0ad5143af445a1e539aada6eb947dd1"}, - {file = "virtualenv-20.19.0.tar.gz", hash = "sha256:37a640ba82ed40b226599c522d411e4be5edb339a0c0de030c0dc7b646d61590"}, + {file = "virtualenv-20.20.0-py3-none-any.whl", hash = "sha256:3c22fa5a7c7aa106ced59934d2c20a2ecb7f49b4130b8bf444178a16b880fa45"}, + {file = "virtualenv-20.20.0.tar.gz", hash = "sha256:a8a4b8ca1e28f864b7514a253f98c1d62b64e31e77325ba279248c65fb4fcef4"}, ] [package.dependencies] @@ -2807,4 +2830,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.10,<4.0.0" -content-hash = "15a585b44a2065b8e7faaa7215d525d839d67b3d349da69eaf84dec6c0ba68e3" +content-hash = "1235a5dd8c759eeff697bcc5572ac8b83a3882636fafa943a3274914a7041060" diff --git a/pyproject.toml b/pyproject.toml index 787fb43..f9799de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,14 +10,14 @@ readme = "README.md" packages = [{ include = "nonebot_bison", from = "./src/plugins/" }] include = ["src/plugins/nonebot_bison/admin_page/dist/**/*"] classifiers = [ - "Development Status :: 4 - Beta", - "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows", - "Operating System :: MacOS", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: CPython", - "License :: OSI Approved :: MIT License", + "Development Status :: 4 - Beta", + "Operating System :: POSIX :: Linux", + "Operating System :: Microsoft :: Windows", + "Operating System :: MacOS", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "License :: OSI Approved :: MIT License", ] [tool.poetry.dependencies] @@ -36,19 +36,20 @@ nonebot-plugin-htmlrender = ">=0.2.0" nonebot-plugin-datastore = ">=0.5.8" nonebot-plugin-apscheduler = "^0.2.0" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] ipdb = "^0.13.4" pytest = "^7.0.1" pytest-asyncio = "^0.18.1" respx = "^0.20.0" pytest-cov = "^3.0.0" -nonebug = "^0.2.3" black = "^22.1.0" isort = "^5.10.1" pre-commit = "^2.17.0" flaky = "^3.7.0" sqlalchemy-stubs = "^0.4" nonebot2 = { extras = ["fastapi"], version = ">=2.0.0-rc.2" } +pytest-mock = "^3.10.0" +nonebug = { git = "https://github.com/nonebot/nonebug.git", rev = "master" } [build-system] requires = ["poetry>=0.12"] @@ -56,9 +57,9 @@ build-backend = "poetry.masonry.api" [tool.pytest.ini_options] markers = [ - "compare: compare fetching result with rsshub", - "render: render img by chrome", - "external: use external resources", + "compare: compare fetching result with rsshub", + "render: render img by chrome", + "external: use external resources", ] asyncio_mode = "auto" @@ -76,3 +77,14 @@ skip_gitignore = true [tool.nonebot] plugins = ["src.plugins.nonebot_bison"] + +[tool.pyright] +pythonVersion = "3.10" +pythonPlatform = "All" +executionEnvironments = [ + { root = "./tests", extraPaths = [ + "./", + "./src/plugins/", + ] }, + { root = "./" }, +] diff --git a/src/plugins/nonebot_bison/platform/mcbbsnews.py b/src/plugins/nonebot_bison/platform/mcbbsnews.py index 030c5ab..f8020ab 100644 --- a/src/plugins/nonebot_bison/platform/mcbbsnews.py +++ b/src/plugins/nonebot_bison/platform/mcbbsnews.py @@ -1,13 +1,12 @@ import re import time import traceback -from typing import Literal from bs4 import BeautifulSoup, Tag from httpx import AsyncClient +from nonebot.log import logger from nonebot.plugin import require -from ..plugin_config import plugin_config from ..post import Post from ..types import Category, RawPost, Target from ..utils import SchedulerConfig, http_client @@ -183,8 +182,11 @@ class McbbsNews(NewMessage): ) assert pic_data except: + err_info = traceback.format_exc() + logger.warning(f"渲染错误:{err_info}") + err_pic0 = await text_to_pic("错误发生!") - err_pic1 = await text_to_pic(traceback.format_exc()) + err_pic1 = await text_to_pic(err_info) return [err_pic0, err_pic1] else: return [pic_data] diff --git a/tests/config/test_config_legacy.py b/tests/config/test_config_legacy.py index 42a430d..9d7d10a 100644 --- a/tests/config/test_config_legacy.py +++ b/tests/config/test_config_legacy.py @@ -1,4 +1,5 @@ import typing +from pathlib import Path import pytest from nonebug.app import App @@ -16,7 +17,11 @@ def config_legacy(app: App, use_legacy_config): from nonebot_bison.config import config_legacy as config config.start_up() - return config.Config() + yield config.Config() + + config.Config().db.close() + legacy_config = Path(config.get_config_path()[0]) + legacy_config.unlink(missing_ok=True) def test_create_and_get(config_legacy: "Config", app: App): diff --git a/tests/config/test_scheduler_conf.py b/tests/config/test_scheduler_conf.py index 2dabf53..6b43b93 100644 --- a/tests/config/test_scheduler_conf.py +++ b/tests/config/test_scheduler_conf.py @@ -1,9 +1,10 @@ from datetime import time from nonebug import App +from pytest_mock import MockerFixture -async def test_create_config(app: App, init_scheduler): +async def test_create_config(init_scheduler): from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig, config from nonebot_bison.config.db_model import Subscribe, Target, User from nonebot_bison.types import Target as T_Target @@ -52,7 +53,7 @@ async def test_create_config(app: App, init_scheduler): assert test_config1.time_config == [] -async def test_get_current_weight(app: App, init_scheduler): +async def test_get_current_weight(init_scheduler, mocker: MockerFixture): from datetime import time from nonebot_bison.config import db_config @@ -99,19 +100,19 @@ async def test_get_current_weight(app: App, init_scheduler): ], ), ) - app.monkeypatch.setattr(db_config, "_get_time", lambda: time(1, 30)) + mocker.patch.object(db_config, "_get_time", return_value=time(1, 30)) weight = await config.get_current_weight_val(["weibo", "bilibili"]) assert len(weight) == 3 assert weight["weibo-weibo_id"] == 20 assert weight["weibo-weibo_id1"] == 10 assert weight["bilibili-weibo_id1"] == 10 - app.monkeypatch.setattr(db_config, "_get_time", lambda: time(4, 0)) + mocker.patch.object(db_config, "_get_time", return_value=time(4, 0)) weight = await config.get_current_weight_val(["weibo", "bilibili"]) assert len(weight) == 3 assert weight["weibo-weibo_id"] == 30 assert weight["weibo-weibo_id1"] == 10 assert weight["bilibili-weibo_id1"] == 10 - app.monkeypatch.setattr(db_config, "_get_time", lambda: time(5, 0)) + mocker.patch.object(db_config, "_get_time", return_value=time(5, 0)) weight = await config.get_current_weight_val(["weibo", "bilibili"]) assert len(weight) == 3 assert weight["weibo-weibo_id"] == 10 diff --git a/tests/conftest.py b/tests/conftest.py index b953e28..a6d249f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,29 +1,67 @@ -import asyncio -import typing +import sys from pathlib import Path import nonebot import pytest -from nonebug.app import App -from sqlalchemy.ext.asyncio.session import AsyncSession -from sqlalchemy.sql.expression import delete +from nonebug import NONEBOT_INIT_KWARGS, App +from pytest_mock.plugin import MockerFixture +from sqlalchemy import delete + +from .utils import AppReq + + +def pytest_configure(config: pytest.Config) -> None: + config.stash[NONEBOT_INIT_KWARGS] = { + "datastore_database_url": "sqlite+aiosqlite:///:memory:", + "superusers": {"10001"}, + "command_start": {""}, + "log_level": "TRACE", + } @pytest.fixture -async def app(nonebug_init: None, tmp_path: Path, monkeypatch: pytest.MonkeyPatch): - import nonebot +async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixture): + sys.path.append(str(Path(__file__).parent.parent / "src" / "plugins")) - config = nonebot.get_driver().config - config.bison_config_path = str(tmp_path / "legacy_config") - config.datastore_config_dir = str(tmp_path / "config") - config.datastore_cache_dir = str(tmp_path / "cache") - config.datastore_data_dir = str(tmp_path / "data") - config.command_start = {""} - config.superusers = {"10001"} - config.log_level = "TRACE" - config.bison_filter_log = False nonebot.require("nonebot_bison") - return App(monkeypatch) + from nonebot_bison import plugin_config + from nonebot_bison.config.db_model import ( + ScheduleTimeWeight, + Subscribe, + Target, + User, + ) + from nonebot_plugin_datastore.config import plugin_config as datastore_config + from nonebot_plugin_datastore.db import create_session, init_db + from nonebot_plugin_htmlrender.browser import shutdown_browser + + plugin_config.bison_config_path = str(tmp_path / "legacy_config") + plugin_config.bison_filter_log = False + + datastore_config.datastore_config_dir = tmp_path / "config" + datastore_config.datastore_cache_dir = tmp_path / "cache" + datastore_config.datastore_data_dir = tmp_path / "data" + + param: AppReq = getattr(request, "param", AppReq()) + + if not param.get("no_init_db"): + await init_db() + if not param.get("refresh_bot"): + import nonebot_bison.utils.get_bot + + mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots") + + yield App() + + # cleanup + async with create_session() as session, session.begin(): + await session.execute(delete(User)) + await session.execute(delete(Subscribe)) + await session.execute(delete(Target)) + await session.execute(delete(ScheduleTimeWeight)) + + # 关闭渲染图片时打开的浏览器 + await shutdown_browser() @pytest.fixture @@ -35,21 +73,7 @@ def dummy_user_subinfo(app: App): @pytest.fixture -async def db_migration(app: App): - from nonebot_bison.config.db_model import Subscribe, Target, User - from nonebot_plugin_datastore.db import get_engine, init_db - - await init_db() - async with AsyncSession(get_engine()) as sess: - await sess.execute(delete(User)) - await sess.execute(delete(Subscribe)) - await sess.execute(delete(Target)) - await sess.commit() - await sess.close() - - -@pytest.fixture -async def init_scheduler(db_migration): +async def init_scheduler(app: App): from nonebot_bison.scheduler.manager import init_scheduler await init_scheduler() diff --git a/tests/platforms/test_weibo.py b/tests/platforms/test_weibo.py index c6bbd5b..33eaab6 100644 --- a/tests/platforms/test_weibo.py +++ b/tests/platforms/test_weibo.py @@ -65,7 +65,6 @@ async def test_fetch_new(weibo, dummy_user_subinfo): assert not detail_router.called mock_data = get_json("weibo_ak_list_1.json") ak_list_router.mock(return_value=Response(200, json=mock_data)) - # import ipdb; ipdb.set_trace() res2 = await weibo.fetch_new_post(target, [dummy_user_subinfo]) assert len(res2) == 0 mock_data["data"]["cards"][1]["mblog"]["created_at"] = datetime.now( diff --git a/tests/scheduler/test_scheduler.py b/tests/scheduler/test_scheduler.py index e4c86b7..0777d9b 100644 --- a/tests/scheduler/test_scheduler.py +++ b/tests/scheduler/test_scheduler.py @@ -3,6 +3,7 @@ from datetime import time from typing import Type from nonebug import App +from pytest_mock import MockerFixture if typing.TYPE_CHECKING: from nonebot_bison.utils.scheduler_config import SchedulerConfig @@ -60,7 +61,7 @@ async def test_scheduler_without_time(init_scheduler): assert static_res["bilibili-live-t2"] == 3 -async def test_scheduler_with_time(app: App, init_scheduler): +async def test_scheduler_with_time(app: App, init_scheduler, mocker: MockerFixture): from nonebot_bison.config import config, db_config from nonebot_bison.config.db_config import TimeWeightConfig, WeightConfig from nonebot_bison.platform.bilibili import BilibiliSchedConf @@ -93,7 +94,8 @@ async def test_scheduler_with_time(app: App, init_scheduler): await init_scheduler() - app.monkeypatch.setattr(db_config, "_get_time", lambda: time(1, 30)) + mocker.patch.object(db_config, "_get_time", return_value=time(1, 30)) + static_res = await get_schedule_times(BilibiliSchedConf, 6) assert static_res["bilibili-t1"] == 1 assert static_res["bilibili-t2"] == 2 @@ -104,7 +106,7 @@ async def test_scheduler_with_time(app: App, init_scheduler): assert static_res["bilibili-t2"] == 2 assert static_res["bilibili-live-t2"] == 3 - app.monkeypatch.setattr(db_config, "_get_time", lambda: time(10, 30)) + mocker.patch.object(db_config, "_get_time", return_value=time(10, 30)) static_res = await get_schedule_times(BilibiliSchedConf, 6) assert static_res["bilibili-t2"] == 6 diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index 6f692eb..70c45d6 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -2,6 +2,7 @@ import pytest import respx from httpx import Response from nonebug.app import App +from pytest_mock import MockerFixture from .platforms.utils import get_json from .utils import BotReply, fake_admin_user, fake_group_message_event @@ -289,7 +290,7 @@ async def test_add_no_target(app: App, init_scheduler): @pytest.mark.asyncio -async def test_platform_name_err(app: App, db_migration): +async def test_platform_name_err(app: App): from nonebot.adapters.onebot.v11.event import Sender from nonebot.adapters.onebot.v11.message import Message from nonebot_bison.config_manager import add_sub_matcher, common_platform @@ -324,7 +325,7 @@ async def test_platform_name_err(app: App, db_migration): @pytest.mark.asyncio @respx.mock -async def test_add_with_get_id(app: App, db_migration): +async def test_add_with_get_id(app: App): from nonebot.adapters.onebot.v11.event import Sender from nonebot.adapters.onebot.v11.message import Message, MessageSegment from nonebot_bison.config import config diff --git a/tests/test_get_bot.py b/tests/test_get_bot.py index 37fb421..3414e13 100644 --- a/tests/test_get_bot.py +++ b/tests/test_get_bot.py @@ -1,8 +1,11 @@ import pytest from nonebug import App +from .utils import AppReq + @pytest.mark.asyncio +@pytest.mark.parametrize("app", [{"refresh_bot": True}], indirect=True) async def test_get_bots(app: App) -> None: from nonebot import get_driver from nonebot.adapters.onebot.v11 import Bot as BotV11 @@ -23,6 +26,7 @@ async def test_get_bots(app: App) -> None: @pytest.mark.asyncio +@pytest.mark.parametrize("app", [{"refresh_bot": True}], indirect=True) async def test_refresh_bots(app: App) -> None: from nonebot import get_driver from nonebot.adapters.onebot.v11 import Bot as BotV11 @@ -57,6 +61,7 @@ async def test_refresh_bots(app: App) -> None: @pytest.mark.asyncio +@pytest.mark.parametrize("app", [{"refresh_bot": True}], indirect=True) async def test_get_bot_two_bots(app: App) -> None: from nonebot import get_driver from nonebot.adapters.onebot.v11 import Bot as BotV11 diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 44a9124..cf0e8fe 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -1,5 +1,7 @@ -import pytest +import importlib + from nonebug import App +from pytest_mock import MockerFixture async def test_without_proxy(app: App): @@ -11,11 +13,15 @@ async def test_without_proxy(app: App): assert "Chrome" in req.headers["User-Agent"] -@pytest.mark.parametrize( - "nonebug_init", [{"bison_proxy": "http://example.com"}], indirect=True -) -async def test_with_proxy(app: App): - from nonebot_bison.utils import http_client +async def test_with_proxy(app: App, mocker: MockerFixture): + from nonebot_bison.plugin_config import plugin_config + + mocker.patch.object(plugin_config, "bison_proxy", "http://example.com") + from nonebot_bison.utils import http + + importlib.reload(http) + + from nonebot_bison.utils.http import http_client c = http_client() assert c._mounts diff --git a/tests/test_send.py b/tests/test_send.py index 7b3eedf..29c30cb 100644 --- a/tests/test_send.py +++ b/tests/test_send.py @@ -4,20 +4,21 @@ import typing import pytest from flaky import flaky from nonebug import App +from pytest_mock.plugin import MockerFixture if typing.TYPE_CHECKING: from nonebot.adapters.onebot.v11.message import Message, MessageSegment @pytest.mark.asyncio -async def test_send_no_queue(app: App): +async def test_send_no_queue(app: App, mocker: MockerFixture): from nonebot.adapters.onebot.v11.bot import Bot from nonebot.adapters.onebot.v11.message import Message from nonebot_bison.plugin_config import plugin_config from nonebot_bison.send import send_msgs + mocker.patch.object(plugin_config, "bison_use_queue", False) async with app.test_api() as ctx: - app.monkeypatch.setattr(plugin_config, "bison_use_queue", False, True) bot = ctx.create_bot(base=Bot) assert isinstance(bot, Bot) ctx.should_call_api( @@ -35,17 +36,18 @@ async def test_send_no_queue(app: App): @pytest.mark.asyncio -@pytest.mark.parametrize("nonebug_init", [{"bison_use_queue": True}], indirect=True) -async def test_send_queue(app: App): +async def test_send_queue(app: App, mocker: MockerFixture): import nonebot from nonebot.adapters.onebot.v11.bot import Bot from nonebot.adapters.onebot.v11.message import Message, MessageSegment from nonebot_bison import send + from nonebot_bison.plugin_config import plugin_config from nonebot_bison.send import MESSGE_SEND_INTERVAL, do_send_msgs, send_msgs + mocker.patch.object(plugin_config, "bison_use_queue", True) async with app.test_api() as ctx: new_bot = ctx.create_bot(base=Bot) - app.monkeypatch.setattr(nonebot, "get_bot", lambda: new_bot, True) + mocker.patch.object(nonebot, "get_bot", lambda: new_bot) bot = nonebot.get_bot() assert isinstance(bot, Bot) assert bot == new_bot diff --git a/tests/utils.py b/tests/utils.py index 38afb26..93434e5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TypedDict from typing_extensions import Literal @@ -6,6 +6,11 @@ if TYPE_CHECKING: from nonebot.adapters.onebot.v11 import GroupMessageEvent, PrivateMessageEvent +class AppReq(TypedDict, total=False): + refresh_bot: bool + no_init_db: bool + + def fake_group_message_event(**field) -> "GroupMessageEvent": from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message from nonebot.adapters.onebot.v11.event import Sender