-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ipc.py
205 lines (190 loc) · 6.07 KB
/
test_ipc.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from pathlib import Path
from sys import platform
from time import sleep
from salve import (
AUTOCOMPLETE,
DEFINITION,
EDITORCONFIG,
HIGHLIGHT,
IPC,
LINKS_AND_CHARS,
REPLACEMENTS,
Response,
)
def test_IPC():
context = IPC()
context.update_file(
"test", open(Path("tests/testing_file1.py"), "r+").read()
)
context.request(
AUTOCOMPLETE,
file="test",
expected_keywords=[],
current_word="t",
)
context.request(
REPLACEMENTS,
file="test",
expected_keywords=[],
current_word="thid",
)
context.request(
HIGHLIGHT, file="test", language="python", text_range=(1, 18)
)
context.request(EDITORCONFIG, file_path=__file__)
context.request(
DEFINITION,
file="test",
current_word="Bar",
definition_starters=[
(r"def ", "after"),
(r"import .*,? ", "after"),
(r"from ", "after"),
(r"class ", "after"),
(r":?.*=.*", "before"),
],
)
context.request(LINKS_AND_CHARS, file="test", text_range=(1, 18))
sleep(1)
# Check output
autocomplete_output: Response | None = context.get_response(AUTOCOMPLETE)
if autocomplete_output is None:
raise AssertionError("Autocomplete output is None")
autocomplete_output["id"] = 0
assert autocomplete_output == {
"id": 0,
"type": "response",
"cancelled": False,
"command": AUTOCOMPLETE,
"result": ["test", "this"],
}
replacements_output: Response | None = context.get_response(REPLACEMENTS)
if replacements_output is None:
raise AssertionError("Replacements output is None")
replacements_output["id"] = 0
assert replacements_output == {
"id": 0,
"type": "response",
"cancelled": False,
"command": REPLACEMENTS,
"result": ["this"],
}
highlight_output: Response | None = context.get_response(HIGHLIGHT)
if highlight_output is None:
raise AssertionError("Highlight output is None")
highlight_output["id"] = 0
expected_output: Response = {
"id": 0,
"type": "response",
"cancelled": False,
"command": HIGHLIGHT,
"result": [
((1, 0), 4, "Keyword"),
((1, 5), 4, "Name"),
((1, 10), 6, "Keyword"),
((1, 17), 1, "Name"),
((1, 20), 12, "Comment"),
((3, 0), 3, "Name"),
((3, 4), 1, "Operator"),
((3, 6), 3, "Name"),
((3, 11), 7, "Comment"),
((5, 0), 5, "Name"),
((5, 5), 1, "Punctuation"),
((5, 6), 3, "String"),
((5, 9), 1, "Punctuation"),
((5, 12), 16, "Comment"),
((8, 0), 5, "Keyword"),
((8, 6), 3, "Name"),
((8, 9), 1, "Punctuation"),
((8, 10), 3, "Name"),
((8, 13), 2, "Punctuation"),
((9, 4), 3, "String"),
((10, 4), 4, "String"),
((11, 4), 3, "String"),
((13, 4), 3, "Keyword"),
((13, 8), 8, "Name"),
((13, 16), 1, "Punctuation"),
((13, 17), 4, "Name"),
((13, 21), 2, "Punctuation"),
((14, 8), 4, "Keyword"),
((17, 0), 3, "Name"),
((17, 3), 2, "Punctuation"),
((18, 0), 24, "Comment"),
],
}
# Deal with Windows weirdness
if platform == "win32":
expected_output = {
"id": 0,
"type": "response",
"cancelled": False,
"command": HIGHLIGHT,
"result": [
((1, 0), 4, "Keyword"),
((1, 5), 4, "Name"),
((1, 10), 6, "Keyword"),
((1, 17), 1, "Name"),
((1, 20), 12, "Comment"),
((3, 0), 3, "Name"),
((3, 4), 1, "Operator"),
((3, 6), 3, "Name"),
((3, 11), 7, "Comment"),
((5, 0), 5, "Name"),
((5, 5), 1, "Punctuation"),
((5, 6), 5, "String"),
((5, 11), 1, "Punctuation"),
((5, 14), 16, "Comment"),
((8, 0), 5, "Keyword"),
((8, 6), 3, "Name"),
((8, 9), 1, "Punctuation"),
((8, 10), 3, "Name"),
((8, 13), 2, "Punctuation"),
((9, 4), 3, "String"),
((10, 4), 4, "String"),
((11, 4), 3, "String"),
((13, 4), 3, "Keyword"),
((13, 8), 8, "Name"),
((13, 16), 1, "Punctuation"),
((13, 17), 4, "Name"),
((13, 21), 2, "Punctuation"),
((14, 8), 4, "Keyword"),
((17, 0), 3, "Name"),
((17, 3), 2, "Punctuation"),
((18, 0), 24, "Comment"),
],
}
assert highlight_output == expected_output
links_and_hidden_chars_result: Response | None = context.get_response(
LINKS_AND_CHARS
)
if links_and_hidden_chars_result is None:
raise AssertionError("links_and_hidden_chars_result output is None")
links_and_hidden_chars_result["id"] = 0
expected_output = {
"id": 0,
"type": "response",
"cancelled": False,
"command": LINKS_AND_CHARS,
"result": [((18, 2), 22, "Link"), ((5, 7), 1, "Hidden_Char")],
}
if platform == "win32":
expected_output = {
"id": 0,
"type": "response",
"cancelled": False,
"command": LINKS_AND_CHARS,
"result": [((18, 2), 22, "Link")],
}
assert links_and_hidden_chars_result == expected_output
context.update_file(
"foo", open(Path("tests/testing_file2.py"), "r+").read()
)
context.request(HIGHLIGHT, file="foo", language="python")
while not (output := context.get_response(HIGHLIGHT)):
pass
response = output["result"] # type: ignore
assert response != []
context.remove_file("test")
context.kill_IPC()
if __name__ == "__main__":
test_IPC()