@@ -19,8 +19,9 @@ async def _wait_request(fetch, endpoint: str):
19
19
20
20
while (datetime .datetime .now () - start_time ).total_seconds () < 0.9 * TEST_TIMEOUT :
21
21
await asyncio .sleep (SLEEP )
22
- response = await fetch (endpoint )
23
- response .rethrow ()
22
+ response = await fetch (endpoint , raise_error = False )
23
+ if response .code >= 400 :
24
+ response .rethrow ()
24
25
if response .code != 202 :
25
26
return response
26
27
@@ -142,6 +143,54 @@ async def test_post_erroneous_execute(jp_fetch, pending_kernel_is_ready, snippet
142
143
assert response2 .code == 204
143
144
144
145
146
+ @pytest .mark .timeout (TEST_TIMEOUT )
147
+ async def test_post_input_execute (jp_fetch , pending_kernel_is_ready ):
148
+ # Start the first kernel
149
+ r = await jp_fetch (
150
+ "api" , "kernels" , method = "POST" , body = json .dumps ({"name" : NATIVE_KERNEL_NAME })
151
+ )
152
+ kernel = json .loads (r .body .decode ())
153
+ await pending_kernel_is_ready (kernel ["id" ])
154
+
155
+ response = await jp_fetch (
156
+ "api" ,
157
+ "kernels" ,
158
+ kernel ["id" ],
159
+ "execute" ,
160
+ method = "POST" ,
161
+ body = json .dumps ({"code" : "input('Age:')" }),
162
+ )
163
+ assert response .code == 202
164
+ location = response .headers ["Location" ]
165
+
166
+ response2 = await _wait_request (jp_fetch , location )
167
+
168
+ assert response2 .code == 300
169
+ payload = json .loads (response2 .body )
170
+ assert "parent_header" in payload
171
+ assert payload ["input_request" ] == {"prompt" : "Age:" , "password" : False }
172
+
173
+ response3 = await jp_fetch (
174
+ "api" , "kernels" , kernel ["id" ], "input" , method = "POST" , body = json .dumps ({"input" : "42" })
175
+ )
176
+ assert response3 .code == 201
177
+
178
+ response4 = await _wait_request (
179
+ jp_fetch ,
180
+ location
181
+ )
182
+ assert response4 .code == 200
183
+ payload2 = json .loads (response4 .body )
184
+ assert payload2 == {
185
+ "status" : "ok" ,
186
+ "execution_count" : 1 ,
187
+ "outputs" : '[{"output_type": "execute_result", "metadata": {}, "data": {"text/plain": "\' 42\' "}, "execution_count": 1}]' ,
188
+ }
189
+
190
+ r2 = await jp_fetch ("api" , "kernels" , kernel ["id" ], method = "DELETE" )
191
+ assert r2 .code == 204
192
+
193
+
145
194
# FIXME
146
195
# @pytest.mark.timeout(TEST_TIMEOUT)
147
196
# async def test_cancel_execute(jp_fetch, pending_kernel_is_ready):
0 commit comments