Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Sep 3, 2024
2 parents e78e361 + f8e1eb2 commit 28047b1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/builtins/plugins/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def _(name: Match[str]):
try:
locales = lang.locales_in(name.result) if name.available else lang.locales
except KeyError:
await cmd.finish(Lang.nbp_alc_builtin.lang.config_name_error(name=name.result))
await cmd.finish(UniMessage.i18n(Lang.nbp_alc_builtin.lang.config_name_error, name=name.result))
else:
await cmd.finish(Lang.nbp_alc_builtin.lang.list() + "\n" + "\n".join(f" * {locale}" for locale in locales))

Expand Down
65 changes: 65 additions & 0 deletions tests/test_builtin_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,68 @@ async def tt_h():
event2 = fake_message_event_satori(message=msg2, id=125)
ctx.receive_event(bot, event2)
ctx.should_call_send(event2, Message("test \ntest"))


@pytest.mark.asyncio()
async def test_lang_switch(app: App):
from tarina.lang import lang

from nonebot_plugin_alconna import load_builtin_plugin

load_builtin_plugin("lang")

async with app.test_matcher() as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
event1 = fake_message_event_satori(message=Message("/lang switch zh-CN"), id=123)
ctx.receive_event(bot, event1)
ctx.should_call_send(event1, Message("切换语言成功: 'zh-CN'。"))
ctx.should_finished()
assert lang.current == "zh-CN"


# @pytest.mark.asyncio()
# async def test_lang_list_success(app: App):
# from tarina.lang import _LangConfigData, lang

# from nonebot_plugin_alconna import load_builtin_plugin

# load_builtin_plugin("lang")

# lang.__dict__["_LangConfig__configs"]["test-lang"] = _LangConfigData(
# default="zh-CN", frozen={}, require={}, name=None, locales={"zh-CN"}
# )

# async with app.test_matcher() as ctx:
# adapter = get_adapter(Adapter)
# bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
# lang.select("zh-CN")
# event = fake_message_event_satori(message=Message("/lang list test-lang"), id=123)
# ctx.receive_event(bot, event)
# ctx.should_call_send(
# event,
# Message("""\
# 支持的语言列表:
# * zh-CN"""),
# )
# ctx.should_finished()


@pytest.mark.asyncio()
async def test_lang_list_failure(app: App):
from tarina.lang import lang

from nonebot_plugin_alconna import load_builtin_plugin

load_builtin_plugin("lang")

async with app.test_matcher() as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, login=FAKE_SATORI_LOGIN, info=None)
lang.select("zh-CN")
event = fake_message_event_satori(message=Message("/lang list 404"), id="123")
ctx.receive_event(bot, event)
ctx.should_call_send(
event, Message((MessageSegment.at("1"), MessageSegment.text(" 未能找到 404 所属的 i18n 目录")))
)
ctx.should_finished()

0 comments on commit 28047b1

Please sign in to comment.