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
206
207
208
209
210
211
212
213
214
215
216
217
218
# SPDX-FileCopyrightText: 2021-2023 Constantine Evans <qslib@mb.costi.net>
# SPDX-License-Identifier: EUPL-1.2
=
await
= await
=
continue
continue
await
return
return
await
await
await
await
await
await
await
await
await
await
await
await
await
await
await
await
await
await
break
return
# # @pytest.mark.parametrize("ssl", [True, False])
# @pytest.mark.asyncio
# async def test_responses():
# srv = await asyncio.start_server(crcb({}), "localhost", 53533)
# async with srv:
# m = Machine("localhost", port=53533, ssl=False)
# m.connect()
# with pytest.raises(Exception):
# m.run_command("TESTERRORSERVER")
# m.run_command("TESTUNKNOWNRESPSERVER")
# # FIXME: this should check logs
# m.run_command_to_ack("TESTNEXTSERVER")
# m.run_command("TESTNEXTSERVER")
# m.run_command("TESTNEXTSERVERDELAY")
# m.disconnect()
# @pytest.mark.asyncio
# async def test_connection():
# srv = await asyncio.start_server(crcb({}), "localhost", 53533)
# async with srv:
# m = Machine("localhost", port=53533, ssl=False)
# assert m.connected is False
# m.connect()
# assert m.connected is True
# m.disconnect()
# assert m.connected is False
# m = Machine("localhost", port=53533, ssl=False)
# m.connect()
# assert m.connected is True
# assert m._connection is not None
# m._connection._protocol.waiting_commands.append((b"12345", None))
# with pytest.raises(ConnectionError):
# m.run_command_bytes(b"TESTKILLSERVER")
# assert m.connected is False
# @pytest.mark.asyncio
# async def test_acc_level_set():
# srv = await asyncio.start_server(crcb({}), "localhost", 53533)
# async with srv:
# m = Machine("localhost", port=53533, ssl=False)
# with m:
# with m.at_access("Observer"):
# assert m.get_access_level() == ("Observer", False, False)
# m.set_access_level("Observer")
# @pytest.mark.asyncio
# async def test_runtitle():
# srv = await asyncio.start_server(crcb({"RUNTitle?": "aoeu"}), "localhost", 53533)
# async with srv:
# with Machine("localhost", port=53533, ssl=False) as m:
# assert m.current_run_name == "aoeu"
# @pytest.mark.asyncio
# async def test_runtitle_not_running():
# srv = await asyncio.start_server(crcb({"RUNTitle?": "-"}), "localhost", 53533)
# async with srv:
# with Machine("localhost", port=53533, ssl=False) as m:
# assert m.current_run_name is None
# @pytest.mark.asyncio
# async def test_quote():
# msg = "<quote>a\nu\n\n \n <quote.2>C\n</quote.2>\n </quote>"
# srv = await asyncio.start_server(crcb({"TESTQUOTE": msg}), "localhost", 53533)
# async with srv:
# with Machine("localhost", port=53533, ssl=False) as m:
# assert m.run_command("TESTQUOTE") == msg
# @pytest.mark.skip # FIXME
# @pytest.mark.asyncio
# async def test_invalid_quote():
# msg = "<quote>a\nu\n</quote.2>\n </quote>"
# srv = await asyncio.start_server(crcb({"TESTQUOTE": msg}), "localhost", 53533)
# async with srv:
# with Machine("localhost", port=53533, ssl=False) as m:
# with pytest.raises(ConnectionError):
# m.run_command("TESTQUOTE")
# @pytest.mark.asyncio
# async def test_nonuid_nonreturn():
# srv = await asyncio.start_server(crcb({}), "localhost", 53533)
# async with srv:
# qsa = QSConnection("localhost", 53533, ssl=False)
# assert qsa.connected is False
# async with qsa:
# assert b"return message\n" == await qsa.run_command(
# "TESTNEXTSERVER", uid=False, just_ack=False
# )
# qsa._protocol.waiting_commands.append((b"12345", None))
# await qsa._protocol.run_command("DOUBLEOK")