2
2
// Licensed under the MIT License.
3
3
'use strict' ;
4
4
import { expect } from 'chai' ;
5
- import { anything , instance , mock , when } from 'ts-mockito' ;
5
+ import { anything , instance , mock , verify , when } from 'ts-mockito' ;
6
6
import { ConfigurationChangeEvent , Disposable , EventEmitter , TextEditor , Uri } from 'vscode' ;
7
7
8
+ import { nbformat } from '@jupyterlab/coreutils' ;
8
9
import * as sinon from 'sinon' ;
9
10
import { ApplicationShell } from '../../../client/common/application/applicationShell' ;
10
11
import { CommandManager } from '../../../client/common/application/commandManager' ;
@@ -24,7 +25,7 @@ import { ConfigurationService } from '../../../client/common/configuration/servi
24
25
import { LiveShareApi } from '../../../client/common/liveshare/liveshare' ;
25
26
import { FileSystem } from '../../../client/common/platform/fileSystem' ;
26
27
import { IFileSystem } from '../../../client/common/platform/types' ;
27
- import { IConfigurationService } from '../../../client/common/types' ;
28
+ import { IConfigurationService , Version } from '../../../client/common/types' ;
28
29
import { CodeCssGenerator } from '../../../client/datascience/codeCssGenerator' ;
29
30
import { DataViewerProvider } from '../../../client/datascience/data-viewing/dataViewerProvider' ;
30
31
import { DataScienceErrorHandler } from '../../../client/datascience/errorHandler/errorHandler' ;
@@ -55,6 +56,7 @@ import { IInterpreterService } from '../../../client/interpreter/contracts';
55
56
import { InterpreterService } from '../../../client/interpreter/interpreterService' ;
56
57
import { createEmptyCell } from '../../../datascience-ui/interactive-common/mainState' ;
57
58
import { waitForCondition } from '../../common' ;
59
+ import { noop } from '../../core' ;
58
60
import { MockMemento } from '../../mocks/mementos' ;
59
61
60
62
// tslint:disable: no-any chai-vague-errors no-unused-expression
@@ -324,7 +326,6 @@ suite('Data Science - Native Editor', () => {
324
326
325
327
return editor ;
326
328
}
327
-
328
329
test ( 'Editing a notebook will save uncommitted changes into memento' , async ( ) => {
329
330
const file = Uri . parse ( 'file://foo.ipynb' ) ;
330
331
@@ -416,4 +417,40 @@ suite('Data Science - Native Editor', () => {
416
417
expect ( newEditor . contents ) . to . be . equal ( baseFile ) ;
417
418
expect ( newEditor . cells ) . to . be . lengthOf ( 3 ) ;
418
419
} ) ;
420
+
421
+ test ( 'Pyton version info will be updated in notebook when a cell has been executed' , async ( ) => {
422
+ const file = Uri . parse ( 'file://foo.ipynb' ) ;
423
+
424
+ const editor = createEditor ( ) ;
425
+ await editor . load ( baseFile , file ) ;
426
+ expect ( editor . contents ) . to . be . equal ( baseFile ) ;
427
+ // At the begining version info is NOT in the file (at least not the same as what we are using to run cells).
428
+ let contents = JSON . parse ( editor . contents ) as nbformat . INotebookContent ;
429
+ expect ( contents . metadata ! . language_info ! . version ) . to . not . equal ( '10.11.12' ) ;
430
+
431
+ // When a cell is executed, then ensure we store the python version info in the notebook data.
432
+ const version : Version = { build : [ ] , major : 10 , minor : 11 , patch : 12 , prerelease : [ ] , raw : '10.11.12' } ;
433
+ when ( executionProvider . getUsableJupyterPython ( ) ) . thenResolve ( ( { version} as any ) ) ;
434
+
435
+ try {
436
+ editor . onMessage ( InteractiveWindowMessages . SubmitNewCell , { code : 'hello' , id : '1' } ) ;
437
+ } catch {
438
+ // Ignore errors related to running cells, assume that works.
439
+ noop ( ) ;
440
+ }
441
+
442
+ // Wait for the version info to be retrieved (done in the background).
443
+ await waitForCondition ( async ( ) => {
444
+ try {
445
+ verify ( executionProvider . getUsableJupyterPython ( ) ) . atLeast ( 1 ) ;
446
+ return true ;
447
+ } catch {
448
+ return false ;
449
+ }
450
+ } , 5_000 , 'Timeout' ) ;
451
+
452
+ // Verify the version info is in the notbook.
453
+ contents = JSON . parse ( editor . contents ) as nbformat . INotebookContent ;
454
+ expect ( contents . metadata ! . language_info ! . version ) . to . equal ( '10.11.12' ) ;
455
+ } ) ;
419
456
} ) ;
0 commit comments