File: test_repl_client.py

package info (click to toggle)
qtile 0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,004 kB
  • sloc: python: 49,959; ansic: 4,371; xml: 324; sh: 260; makefile: 218
file content (42 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download
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
import pytest

from libqtile.scripts.repl import TERMINATOR, is_code_complete, read_full_response


class MockSocket:
    def recv(self, *args, **kwargs):
        return (f"Qtile test\nREPL client\n{TERMINATOR}\n").encode()


def test_read_full_response_basic():
    # Create a mock socket with recv method
    sock = MockSocket()

    response = read_full_response(sock)
    assert "Qtile test" in response
    assert "REPL client" in response
    # The terminator should be stripped off
    assert TERMINATOR not in response


@pytest.mark.parametrize(
    "input,valid",
    [
        ("x+1", True),
        ("def a():", False),
        ("def a():\n  print(1)", False),
        ("def a():\n  print(1)\n", True),
        ("def a():\n  print(1)\ndef b():\n  print(2)\n", True),
        ("while True:\n", False),
    ],
    ids=[
        "SingleExpression",
        "IncompleteFunction",
        "MultilineIncomplete",
        "MultilineComplete",
        "MultiMultiline",
        "IncompleteContext",
    ],
)
def test_is_code_complete(input, valid):
    assert is_code_complete(f"{input}\n") is valid