summaryrefslogtreecommitdiff
path: root/test/test_plugin_code_runner.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_plugin_code_runner.py')
-rw-r--r--test/test_plugin_code_runner.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test_plugin_code_runner.py b/test/test_plugin_code_runner.py
new file mode 100644
index 0000000..584ebb0
--- /dev/null
+++ b/test/test_plugin_code_runner.py
@@ -0,0 +1,75 @@
+import pytest
+from nonebug import App
+
+from .utils import make_fake_message, make_fake_event
+
+
+async def test_code_runner(app: App):
+ from ATRI.plugins.code_runner import code_runner
+
+ Message = make_fake_message()
+
+ async with app.test_matcher(code_runner) as ctx:
+ bot = ctx.create_bot()
+
+ msg = Message("/code")
+ event = make_fake_event(_message=msg)()
+
+ ctx.receive_event(bot, event)
+ ctx.should_call_send(event, "请键入 /code help 以获取帮助~!", True)
+
+ async with app.test_matcher(code_runner) as ctx:
+ bot = ctx.create_bot()
+
+ msg = Message("/code help")
+ event = make_fake_event(_message=msg)()
+
+ ctx.receive_event(bot, event)
+ ctx.should_call_send(
+ event,
+ """
+ /code {语言}
+ {代码}
+ For example:
+ /code python
+ print('hello world')
+ """,
+ True,
+ )
+
+ async with app.test_matcher(code_runner) as ctx:
+ bot = ctx.create_bot()
+
+ msg = Message("/code list")
+ event = make_fake_event(_message=msg)()
+
+ ctx.receive_event(bot, event)
+ ctx.should_call_send(
+ event,
+ """
+ 咱现在支持的语言如下:
+ assembly, bash, c, clojure,
+ coffeescript, cpp, csharp,
+ erlang, fsharp, go, groovy,
+ haskell, java, javascript,
+ julia, kotlin, lua, perl,
+ php, python, ruby, rust,
+ scala, swift, typescript
+ """,
+ True,
+ )
+
+ async with app.test_matcher(code_runner) as ctx:
+ bot = ctx.create_bot()
+
+ msg = Message(
+ """
+ /code python
+ print("hello world")
+ """
+ )
+ event = make_fake_event(_message=msg)()
+
+ ctx.receive_event(bot, event)
+ ctx.should_call_send(event, "stdout:\nhello world", True)