@@ -221,9 +221,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
221
221
expect ( displayCell . metadata . lastRunDuration ) . to . be . greaterThan ( 0 , 'Duration should be > 0' ) ;
222
222
expect ( markdownOutput . data [ 'text/markdown' ] ) . to . be . equal ( 'foo' , 'Display cell did not update' ) ;
223
223
} ) ;
224
- test ( 'Clearing output while executing will ensure output is cleared' , async function ( ) {
225
- // https://github.com/microsoft/vscode-python/issues/12302
226
- return this . skip ( ) ;
224
+ test ( 'Clearing output while executing will ensure output is cleared' , async ( ) => {
227
225
// Assume you are executing a cell that prints numbers 1-100.
228
226
// When printing number 50, you click clear.
229
227
// Cell output should now start printing output from 51 onwards, & not 1.
@@ -235,24 +233,35 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
235
233
time.sleep(0.1)
236
234
print(i)
237
235
238
- print("End")`
236
+ print("End")` ,
237
+ 0
239
238
) ;
240
239
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
241
240
242
241
await executeActiveDocument ( ) ;
243
242
244
- // Wait till execution count changes and status is error .
243
+ // Wait till we get the desired output .
245
244
await waitForCondition (
246
- async ( ) => assertHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) ,
245
+ async ( ) =>
246
+ assertHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) &&
247
+ assertHasTextOutputInVSCode ( cell , '0' , 0 , false ) &&
248
+ assertHasTextOutputInVSCode ( cell , '1' , 0 , false ) &&
249
+ assertHasTextOutputInVSCode ( cell , '2' , 0 , false ) &&
250
+ assertHasTextOutputInVSCode ( cell , '3' , 0 , false ) &&
251
+ assertHasTextOutputInVSCode ( cell , '4' , 0 , false ) ,
247
252
15_000 ,
248
253
'Cell did not get executed'
249
254
) ;
250
255
251
256
// Clear the cells
252
257
await commands . executeCommand ( 'notebook.clearAllCellsOutputs' ) ;
253
- // Wait till execution count changes and status is error.
258
+
259
+ // Wait till previous output gets cleared & we have new output.
254
260
await waitForCondition (
255
- async ( ) => assertNotHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) ,
261
+ async ( ) =>
262
+ assertNotHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) &&
263
+ cell . outputs . length > 0 &&
264
+ cell . outputs [ 0 ] . outputKind === vscodeNotebookEnums . CellOutputKind . Rich ,
256
265
5_000 ,
257
266
'Cell did not get cleared'
258
267
) ;
@@ -264,4 +273,74 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
264
273
// Verify that it hasn't got added (even after interrupting).
265
274
assertNotHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) ;
266
275
} ) ;
276
+ test ( 'Clearing output via code' , async ( ) => {
277
+ // Assume you are executing a cell that prints numbers 1-100.
278
+ // When printing number 50, you click clear.
279
+ // Cell output should now start printing output from 51 onwards, & not 1.
280
+ await insertPythonCellAndWait (
281
+ dedent `
282
+ from IPython.display import display, clear_output
283
+ import time
284
+ print('foo')
285
+ display('foo')
286
+ time.sleep(2)
287
+ clear_output(True)
288
+ print('bar')
289
+ display('bar')` ,
290
+ 0
291
+ ) ;
292
+ const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
293
+
294
+ await executeActiveDocument ( ) ;
295
+
296
+ // Wait for foo to be printed
297
+ await waitForCondition (
298
+ async ( ) =>
299
+ assertHasTextOutputInVSCode ( cell , 'foo' , 0 , false ) &&
300
+ assertHasTextOutputInVSCode ( cell , 'foo' , 1 , false ) ,
301
+ 15_000 ,
302
+ 'Incorrect output'
303
+ ) ;
304
+
305
+ // Wait for bar to be printed
306
+ await waitForCondition (
307
+ async ( ) =>
308
+ assertHasTextOutputInVSCode ( cell , 'bar' , 0 , false ) &&
309
+ assertHasTextOutputInVSCode ( cell , 'bar' , 1 , false ) ,
310
+ 15_000 ,
311
+ 'Incorrect output'
312
+ ) ;
313
+ } ) ;
314
+ test ( 'Testing streamed output' , async ( ) => {
315
+ // Assume you are executing a cell that prints numbers 1-100.
316
+ // When printing number 50, you click clear.
317
+ // Cell output should now start printing output from 51 onwards, & not 1.
318
+ await insertPythonCellAndWait (
319
+ dedent `
320
+ print("Start")
321
+ import time
322
+ for i in range(5):
323
+ time.sleep(0.5)
324
+ print(i)
325
+
326
+ print("End")` ,
327
+ 0
328
+ ) ;
329
+ const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
330
+
331
+ await executeActiveDocument ( ) ;
332
+
333
+ await waitForCondition (
334
+ async ( ) =>
335
+ assertHasTextOutputInVSCode ( cell , 'Start' , 0 , false ) &&
336
+ assertHasTextOutputInVSCode ( cell , '0' , 0 , false ) &&
337
+ assertHasTextOutputInVSCode ( cell , '1' , 0 , false ) &&
338
+ assertHasTextOutputInVSCode ( cell , '2' , 0 , false ) &&
339
+ assertHasTextOutputInVSCode ( cell , '3' , 0 , false ) &&
340
+ assertHasTextOutputInVSCode ( cell , '4' , 0 , false ) &&
341
+ assertHasTextOutputInVSCode ( cell , 'End' , 0 , false ) ,
342
+ 15_000 ,
343
+ 'Incorrect output'
344
+ ) ;
345
+ } ) ;
267
346
} ) ;
0 commit comments