Skip to content

Commit 95012fd

Browse files
authored
style: 更新 ruff 配置 (#108)
移除 isort 和 black,仅使用 ruff 进行格式化。
1 parent 1f7ec3b commit 95012fd

File tree

8 files changed

+25
-48
lines changed

8 files changed

+25
-48
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@ ci:
66
autoupdate_commit_msg: "chore: auto update by pre-commit hooks"
77
repos:
88
- repo: https://github.com/astral-sh/ruff-pre-commit
9-
rev: v0.1.9
9+
rev: v0.2.2
1010
hooks:
1111
- id: ruff
1212
args: [--fix, --exit-non-zero-on-fix]
1313
stages: [commit]
14-
15-
- repo: https://github.com/pycqa/isort
16-
rev: 5.13.2
17-
hooks:
18-
- id: isort
19-
stages: [commit]
20-
21-
- repo: https://github.com/psf/black
22-
rev: 23.12.1
23-
hooks:
24-
- id: black
25-
stages: [commit]
14+
- id: ruff-format
2615

2716
- repo: https://github.com/pre-commit/mirrors-prettier
2817
rev: v4.0.0-alpha.8

nonebot_plugin_user/matchers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def _(
109109
session.level,
110110
)
111111
await bind_cmd.finish(
112-
f"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind {token}\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。"
112+
f"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind {token}\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。" # noqa: E501
113113
)
114114

115115
# 绑定流程
@@ -122,7 +122,7 @@ async def _(
122122
token = generate_token()
123123
tokens[token] = (session.platform, session.platform_id, user_id, None)
124124
await bind_cmd.finish(
125-
f"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind {token}\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。"
125+
f"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind {token}\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。" # noqa: E501
126126
)
127127
# 群内绑定的第二步,会在目标平台发送令牌
128128
# 此时 platform_id 和 platform 为原始平台的信息

pyproject.toml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ pytest-mock = "^3.10.0"
3232
pytest-asyncio = "^0.23.5"
3333
freezegun = "^1.2.2"
3434

35-
[tool.black]
36-
line-length = 88
37-
38-
[tool.isort]
39-
profile = "black"
40-
line_length = 88
41-
skip_gitignore = true
42-
4335
[tool.pytest.ini_options]
4436
asyncio_mode = "auto"
4537

@@ -50,8 +42,12 @@ typeCheckingMode = "basic"
5042
defineConstant = { PYDANTIC_V2 = true }
5143

5244
[tool.ruff]
53-
select = ["E", "W", "F", "UP", "C", "T", "PYI", "Q"]
54-
ignore = ["E402", "E501", "C901", "UP037"]
45+
line-length = 88
46+
target-version = "py38"
47+
48+
[tool.ruff.lint]
49+
select = ["E", "W", "F", "UP", "C", "T", "PYI", "PT", "Q"]
50+
ignore = ["E402", "C901", "UP037"]
5551

5652
[tool.nonebot]
5753
adapters = [

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def pytest_configure(config: pytest.Config) -> None:
2020

2121

2222
@pytest.fixture(scope="session", autouse=True)
23-
def load_adapters(nonebug_init: None):
23+
def _load_adapters(nonebug_init: None):
2424
driver = nonebot.get_driver()
2525
driver.register_adapter(OnebotV11Adapter)
2626
driver.register_adapter(OnebotV12Adapter)
2727

2828

29-
@pytest.fixture
29+
@pytest.fixture()
3030
async def app(app: App, mocker: MockerFixture, tmp_path: Path):
3131
# 加载插件
3232
nonebot.require("nonebot_plugin_user")
@@ -47,7 +47,7 @@ async def app(app: App, mocker: MockerFixture, tmp_path: Path):
4747
await session.execute(delete(User))
4848

4949

50-
@pytest.fixture
50+
@pytest.fixture()
5151
async def session(app: App):
5252
from nonebot_plugin_orm import get_session
5353

@@ -72,6 +72,6 @@ def set_timestamp(mapper, connection, target):
7272
event.remove(User, "before_insert", set_timestamp)
7373

7474

75-
@pytest.fixture(scope="function")
75+
@pytest.fixture()
7676
def patch_current_time():
7777
return patch_time

tests/test_bind_group.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_bind_group(app: App, patch_current_time, mocker: MockerFixture):
4848
ctx.receive_event(bot, event)
4949
ctx.should_call_send(
5050
event,
51-
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。",
51+
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。", # noqa: E501
5252
True,
5353
)
5454
ctx.should_finished(bind_cmd)
@@ -63,7 +63,7 @@ async def test_bind_group(app: App, patch_current_time, mocker: MockerFixture):
6363
ctx.receive_event(bot, event)
6464
ctx.should_call_send(
6565
event,
66-
"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind nonebot/123456\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。",
66+
"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind nonebot/123456\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。", # noqa: E501
6767
True,
6868
)
6969
ctx.should_finished(bind_cmd)
@@ -150,7 +150,7 @@ async def test_bind_group_different_user(
150150
ctx.receive_event(bot, event)
151151
ctx.should_call_send(
152152
event,
153-
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。",
153+
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。", # noqa: E501
154154
True,
155155
)
156156
ctx.should_finished(bind_cmd)
@@ -165,7 +165,7 @@ async def test_bind_group_different_user(
165165
ctx.receive_event(bot, event)
166166
ctx.should_call_send(
167167
event,
168-
"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind nonebot/123456\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。",
168+
"令牌核验成功!下面将进行第二步操作。\n请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:\n/bind nonebot/123456\n注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。", # noqa: E501
169169
True,
170170
)
171171
ctx.should_finished(bind_cmd)

tests/test_bind_private.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def test_bind_private(app: App, patch_current_time, mocker: MockerFixture)
4848
ctx.receive_event(bot, event)
4949
ctx.should_call_send(
5050
event,
51-
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。",
51+
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。", # noqa: E501
5252
True,
5353
)
5454
ctx.should_finished(bind_cmd)
@@ -135,7 +135,7 @@ async def test_bind_private_invalid_token(
135135
ctx.receive_event(bot, event)
136136
ctx.should_call_send(
137137
event,
138-
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。",
138+
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind nonebot/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。", # noqa: E501
139139
True,
140140
)
141141
ctx.should_finished(bind_cmd)
@@ -223,7 +223,7 @@ async def test_bind_private_prefix(app: App, patch_current_time, mocker: MockerF
223223
ctx.receive_event(bot, event)
224224
ctx.should_call_send(
225225
event,
226-
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind test/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。",
226+
"命令 bind 可用于在多个平台间绑定用户数据。绑定过程中,原始平台的用户数据将完全保留,而目标平台的用户数据将被原始平台的数据所覆盖。\n请确认当前平台是你的目标平台,并在 5 分钟内使用你的账号在原始平台内向机器人发送以下文本:\n/bind test/123456\n绑定完成后,你可以随时使用「bind -r」来解除绑定状态。", # noqa: E501
227227
True,
228228
)
229229
ctx.should_finished(bind_cmd)

tests/test_remove_bind.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ async def test_bind_not_exist(app: App):
7575
"""不存在的账户"""
7676
from nonebot_plugin_user.utils import remove_bind, set_bind
7777

78-
with pytest.raises(ValueError) as e:
78+
with pytest.raises(ValueError, match="找不到用户信息"):
7979
await remove_bind("qq", "1")
8080

81-
assert str(e.value) == "找不到用户信息"
82-
83-
with pytest.raises(ValueError) as e:
81+
with pytest.raises(ValueError, match="找不到用户信息"):
8482
await set_bind("qq", "1", 2)
85-
86-
assert str(e.value) == "找不到用户信息"

tests/test_user.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ async def test_user(app: App, patch_current_time):
4040
user = await get_user_by_id(1)
4141
assert user.id == 1
4242

43-
with pytest.raises(ValueError) as e:
43+
with pytest.raises(ValueError, match="找不到用户信息"):
4444
await get_user_by_id(2)
4545

46-
assert str(e.value) == "找不到用户信息"
47-
4846

4947
async def test_user_set_name(app: App, patch_current_time):
5048
"""设置用户名"""
@@ -116,11 +114,9 @@ async def test_user_set_name(app: App, patch_current_time):
116114
)
117115
ctx.should_finished(user_cmd)
118116

119-
with pytest.raises(ValueError) as e:
117+
with pytest.raises(ValueError, match="找不到用户信息"):
120118
await set_user_name("123", "qq", "not exist")
121119

122-
assert str(e.value) == "找不到用户信息"
123-
124120

125121
async def test_user_session(app: App, patch_current_time):
126122
"""用户会话相关的测试"""

0 commit comments

Comments
 (0)