summaryrefslogtreecommitdiff
path: root/test/test_plugin_code_runner.py
blob: ec9eb2d1be2f5d030d11c6e4e5c55e35b694ba5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pytest
from nonebug import App

from .utils import make_fake_message, make_fake_event


@pytest.mark.asyncio
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')
            """.strip(),
            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
            """.strip(),
            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)