mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-15 07:14:08 +00:00
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import subprocess
|
|
import sys
|
|
|
|
|
|
def _run_import_probe(source: str) -> str:
|
|
proc = subprocess.run(
|
|
[sys.executable, "-c", source],
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
return proc.stdout.strip()
|
|
|
|
|
|
def test_feishu_module_import_does_not_import_lark_oapi():
|
|
out = _run_import_probe(
|
|
"import sys; import nanobot.channels.feishu; print('lark_oapi' in sys.modules)"
|
|
)
|
|
|
|
assert out == "False"
|
|
|
|
|
|
def test_feishu_channel_constructor_does_not_import_lark_oapi():
|
|
out = _run_import_probe(
|
|
"import sys; "
|
|
"from nanobot.bus.queue import MessageBus; "
|
|
"from nanobot.channels.feishu import FeishuChannel; "
|
|
"FeishuChannel({'enabled': True}, MessageBus()); "
|
|
"print('lark_oapi' in sys.modules)"
|
|
)
|
|
|
|
assert out == "False"
|
|
|
|
|
|
def test_lark_runtime_thread_import_clears_sdk_import_loop():
|
|
out = _run_import_probe(
|
|
"import asyncio\n"
|
|
"from nanobot.channels.feishu import _load_lark_runtime\n"
|
|
"async def main():\n"
|
|
" await asyncio.to_thread(_load_lark_runtime)\n"
|
|
" import lark_oapi.ws.client as ws\n"
|
|
" print(getattr(ws, 'loop', 'sentinel') is None)\n"
|
|
"asyncio.run(main())"
|
|
)
|
|
|
|
assert out == "True"
|