@@ -25,7 +25,7 @@ import {
25
25
deleteAllCellsAndWait ,
26
26
executeActiveDocument ,
27
27
executeCell ,
28
- insertPythonCellAndWait ,
28
+ insertPythonCell ,
29
29
startJupyter ,
30
30
trustAllNotebooks
31
31
} from './helper' ;
@@ -56,7 +56,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
56
56
setup ( deleteAllCellsAndWait ) ;
57
57
suiteTeardown ( ( ) => closeNotebooksAndCleanUpAfterTests ( disposables ) ) ;
58
58
test ( 'Execute cell using VSCode Kernel' , async ( ) => {
59
- await insertPythonCellAndWait ( 'print("Hello World")' ) ;
59
+ await insertPythonCell ( 'print("Hello World")' ) ;
60
60
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
61
61
62
62
await executeCell ( cell ) ;
@@ -69,7 +69,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
69
69
) ;
70
70
} ) ;
71
71
test ( 'Executed events are triggered' , async ( ) => {
72
- await insertPythonCellAndWait ( 'print("Hello World")' ) ;
72
+ await insertPythonCell ( 'print("Hello World")' ) ;
73
73
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
74
74
75
75
const executed = createEventHandler ( editorProvider . activeEditor ! , 'executed' , disposables ) ;
@@ -87,7 +87,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
87
87
await codeExecuted . assertFired ( 1_000 ) ;
88
88
} ) ;
89
89
test ( 'Empty cell will not get executed' , async ( ) => {
90
- await insertPythonCellAndWait ( '' ) ;
90
+ await insertPythonCell ( '' ) ;
91
91
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
92
92
await executeCell ( cell ) ;
93
93
@@ -96,8 +96,8 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
96
96
assert . isUndefined ( cell ?. metadata . runState ) ;
97
97
} ) ;
98
98
test ( 'Empty cells will not get executed when running whole document' , async ( ) => {
99
- await insertPythonCellAndWait ( '' ) ;
100
- await insertPythonCellAndWait ( 'print("Hello World")' ) ;
99
+ await insertPythonCell ( '' ) ;
100
+ await insertPythonCell ( 'print("Hello World")' ) ;
101
101
const cells = vscodeNotebook . activeNotebookEditor ?. document . cells ! ;
102
102
103
103
await executeActiveDocument ( ) ;
@@ -111,7 +111,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
111
111
assert . isUndefined ( cells [ 0 ] . metadata . runState ) ;
112
112
} ) ;
113
113
test ( 'Verify Cell output, execution count and status' , async ( ) => {
114
- await insertPythonCellAndWait ( 'print("Hello World")' ) ;
114
+ await insertPythonCell ( 'print("Hello World")' ) ;
115
115
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
116
116
117
117
await executeActiveDocument ( ) ;
@@ -130,8 +130,8 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
130
130
assert . ok ( cell . metadata . executionOrder , 'Execution count should be > 0' ) ;
131
131
} ) ;
132
132
test ( 'Verify multiple cells get executed' , async ( ) => {
133
- await insertPythonCellAndWait ( 'print("Foo Bar")' ) ;
134
- await insertPythonCellAndWait ( 'print("Hello World")' ) ;
133
+ await insertPythonCell ( 'print("Foo Bar")' ) ;
134
+ await insertPythonCell ( 'print("Hello World")' ) ;
135
135
const cells = vscodeNotebook . activeNotebookEditor ?. document . cells ! ;
136
136
137
137
await executeActiveDocument ( ) ;
@@ -153,7 +153,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
153
153
assert . equal ( cells [ 1 ] . metadata . executionOrder ! - 1 , cells [ 0 ] . metadata . executionOrder ! ) ;
154
154
} ) ;
155
155
test ( 'Verify metadata for successfully executed cell' , async ( ) => {
156
- await insertPythonCellAndWait ( 'print("Foo Bar")' ) ;
156
+ await insertPythonCell ( 'print("Foo Bar")' ) ;
157
157
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
158
158
159
159
await executeActiveDocument ( ) ;
@@ -172,7 +172,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
172
172
assert . equal ( cell . metadata . statusMessage , '' , 'Incorrect Status message' ) ;
173
173
} ) ;
174
174
test ( 'Verify output & metadata for executed cell with errors' , async ( ) => {
175
- await insertPythonCellAndWait ( 'print(abcd)' ) ;
175
+ await insertPythonCell ( 'print(abcd)' ) ;
176
176
const cell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 0 ] ! ;
177
177
178
178
await executeActiveDocument ( ) ;
@@ -198,9 +198,9 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
198
198
assert . include ( cell . metadata . statusMessage ! , 'abcd' , 'Must contain error message' ) ;
199
199
} ) ;
200
200
test ( 'Updating display data' , async ( ) => {
201
- await insertPythonCellAndWait ( 'from IPython.display import Markdown\n' ) ;
202
- await insertPythonCellAndWait ( 'dh = display(display_id=True)\n' ) ;
203
- await insertPythonCellAndWait ( 'dh.update(Markdown("foo"))\n' ) ;
201
+ await insertPythonCell ( 'from IPython.display import Markdown\n' ) ;
202
+ await insertPythonCell ( 'dh = display(display_id=True)\n' ) ;
203
+ await insertPythonCell ( 'dh.update(Markdown("foo"))\n' ) ;
204
204
const displayCell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 1 ] ! ;
205
205
const updateCell = vscodeNotebook . activeNotebookEditor ?. document . cells ! [ 2 ] ! ;
206
206
@@ -225,7 +225,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
225
225
// Assume you are executing a cell that prints numbers 1-100.
226
226
// When printing number 50, you click clear.
227
227
// Cell output should now start printing output from 51 onwards, & not 1.
228
- await insertPythonCellAndWait (
228
+ await insertPythonCell (
229
229
dedent `
230
230
print("Start")
231
231
import time
@@ -277,7 +277,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
277
277
// Assume you are executing a cell that prints numbers 1-100.
278
278
// When printing number 50, you click clear.
279
279
// Cell output should now start printing output from 51 onwards, & not 1.
280
- await insertPythonCellAndWait (
280
+ await insertPythonCell (
281
281
dedent `
282
282
from IPython.display import display, clear_output
283
283
import time
@@ -315,7 +315,7 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
315
315
// Assume you are executing a cell that prints numbers 1-100.
316
316
// When printing number 50, you click clear.
317
317
// Cell output should now start printing output from 51 onwards, & not 1.
318
- await insertPythonCellAndWait (
318
+ await insertPythonCell (
319
319
dedent `
320
320
print("Start")
321
321
import time
@@ -344,14 +344,14 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
344
344
) ;
345
345
} ) ;
346
346
test ( 'Verify escaping of output' , async ( ) => {
347
- await insertPythonCellAndWait ( '1' ) ;
348
- await insertPythonCellAndWait ( dedent `
347
+ await insertPythonCell ( '1' ) ;
348
+ await insertPythonCell ( dedent `
349
349
a="<a href=f>"
350
350
a` ) ;
351
- await insertPythonCellAndWait ( dedent `
351
+ await insertPythonCell ( dedent `
352
352
a="<a href=f>"
353
353
print(a)` ) ;
354
- await insertPythonCellAndWait ( 'raise Exception("<whatever>")' ) ;
354
+ await insertPythonCell ( 'raise Exception("<whatever>")' ) ;
355
355
const cells = vscodeNotebook . activeNotebookEditor ?. document . cells ! ;
356
356
357
357
await executeActiveDocument ( ) ;
@@ -391,4 +391,44 @@ suite('DataScience - VSCode Notebook - (Execution) (slow)', function () {
391
391
assert . isNotEmpty ( errorOutput . traceback , 'Incorrect traceback' ) ;
392
392
assert . include ( errorOutput . traceback . join ( '' ) , '<whatever>' ) ;
393
393
} ) ;
394
+ test ( 'Verify display updates' , async ( ) => {
395
+ await insertPythonCell ( 'from IPython.display import Markdown' , 0 ) ;
396
+ await insertPythonCell ( 'dh = display(Markdown("foo"), display_id=True)' , 1 ) ;
397
+ let cells = vscodeNotebook . activeNotebookEditor ?. document . cells ! ;
398
+
399
+ await executeActiveDocument ( ) ;
400
+ await waitForCondition (
401
+ async ( ) => assertHasExecutionCompletedSuccessfully ( cells [ 1 ] ) ,
402
+ 15_000 ,
403
+ 'Cell did not get executed'
404
+ ) ;
405
+
406
+ assert . equal ( cells [ 0 ] . outputs . length , 0 , 'Incorrect number of output' ) ;
407
+ assert . equal ( cells [ 1 ] . outputs . length , 1 , 'Incorrect number of output' ) ;
408
+ assert . equal ( cells [ 1 ] . outputs [ 0 ] . outputKind , vscodeNotebookEnums . CellOutputKind . Rich , 'Incorrect output type' ) ;
409
+ assert . equal ( ( cells [ 1 ] . outputs [ 0 ] as CellDisplayOutput ) . data [ 'text/markdown' ] , 'foo' , 'Incorrect output value' ) ;
410
+ const displayId = ( cells [ 1 ] . outputs [ 0 ] as CellDisplayOutput ) . metadata ?. custom ?. transient ?. display_id ;
411
+ assert . ok ( displayId , 'Display id not present in metadata' ) ;
412
+
413
+ await insertPythonCell (
414
+ dedent `
415
+ dh.update(Markdown("bar"))
416
+ print('hello')` ,
417
+ 2
418
+ ) ;
419
+ await executeActiveDocument ( ) ;
420
+ cells = vscodeNotebook . activeNotebookEditor ?. document . cells ! ;
421
+ await waitForCondition (
422
+ async ( ) => assertHasExecutionCompletedSuccessfully ( cells [ 2 ] ) ,
423
+ 15_000 ,
424
+ 'Cell did not get executed'
425
+ ) ;
426
+
427
+ assert . equal ( cells [ 0 ] . outputs . length , 0 , 'Incorrect number of output' ) ;
428
+ assert . equal ( cells [ 1 ] . outputs . length , 1 , 'Incorrect number of output' ) ;
429
+ assert . equal ( cells [ 2 ] . outputs . length , 1 , 'Incorrect number of output' ) ;
430
+ assert . equal ( cells [ 1 ] . outputs [ 0 ] . outputKind , vscodeNotebookEnums . CellOutputKind . Rich , 'Incorrect output type' ) ;
431
+ assert . equal ( ( cells [ 1 ] . outputs [ 0 ] as CellDisplayOutput ) . data [ 'text/markdown' ] , 'bar' , 'Incorrect output value' ) ;
432
+ assertHasTextOutputInVSCode ( cells [ 2 ] , 'hello' , 0 , false ) ;
433
+ } ) ;
394
434
} ) ;
0 commit comments