3
3
'use strict' ;
4
4
import { nbformat } from '@jupyterlab/coreutils/lib/nbformat' ;
5
5
import { assert } from 'chai' ;
6
- import { anything , instance , mock , when } from 'ts-mockito' ;
6
+ import { anything , instance , mock , verify , when } from 'ts-mockito' ;
7
7
import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher' ;
8
8
import * as TypeMoq from 'typemoq' ;
9
9
import * as uuid from 'uuid/v4' ;
10
10
import { EventEmitter , Uri } from 'vscode' ;
11
11
12
12
import { ApplicationShell } from '../../client/common/application/applicationShell' ;
13
+ import { IApplicationShell } from '../../client/common/application/types' ;
13
14
import { PythonSettings } from '../../client/common/configSettings' ;
14
15
import { ConfigurationService } from '../../client/common/configuration/service' ;
15
16
import { Logger } from '../../client/common/logger' ;
16
17
import { FileSystem } from '../../client/common/platform/fileSystem' ;
17
18
import { IFileSystem } from '../../client/common/platform/types' ;
18
19
import { IConfigurationService , IDisposable , ILogger } from '../../client/common/types' ;
20
+ import * as localize from '../../client/common/utils/localize' ;
19
21
import { generateCells } from '../../client/datascience/cellFactory' ;
20
22
import { Commands } from '../../client/datascience/constants' ;
21
23
import { DataScienceErrorHandler } from '../../client/datascience/errorHandler/errorHandler' ;
24
+ import { NativeEditorProvider } from '../../client/datascience/interactive-ipynb/nativeEditorProvider' ;
22
25
import {
23
26
InteractiveWindowCommandListener
24
27
} from '../../client/datascience/interactive-window/interactiveWindowCommandListener' ;
@@ -28,15 +31,15 @@ import { JupyterExporter } from '../../client/datascience/jupyter/jupyterExporte
28
31
import { JupyterImporter } from '../../client/datascience/jupyter/jupyterImporter' ;
29
32
import {
30
33
IInteractiveWindow ,
34
+ IJupyterExecution ,
31
35
INotebook ,
36
+ INotebookEditorProvider ,
32
37
INotebookServer
33
38
} from '../../client/datascience/types' ;
34
39
import { InterpreterService } from '../../client/interpreter/interpreterService' ;
35
40
import { KnownSearchPathsForInterpreters } from '../../client/interpreter/locators/services/KnownPathsService' ;
36
41
import { ServiceContainer } from '../../client/ioc/container' ;
37
- import { noop } from '../core' ;
38
42
import { MockAutoSelectionService } from '../mocks/autoSelector' ;
39
- import * as vscodeMocks from '../vscode-mock' ;
40
43
import { MockCommandManager } from './mockCommandManager' ;
41
44
import { MockDocumentManager } from './mockDocumentManager' ;
42
45
import { MockStatusProvider } from './mockStatusProvider' ;
@@ -67,26 +70,16 @@ suite('Interactive window command listener', async () => {
67
70
const dataScienceErrorHandler = mock ( DataScienceErrorHandler ) ;
68
71
const notebookImporter = mock ( JupyterImporter ) ;
69
72
const notebookExporter = mock ( JupyterExporter ) ;
70
- const applicationShell = mock ( ApplicationShell ) ;
71
- const jupyterExecution = mock ( JupyterExecutionFactory ) ;
73
+ let applicationShell : IApplicationShell ;
74
+ let jupyterExecution : IJupyterExecution ;
72
75
const interactiveWindow = createTypeMoq < IInteractiveWindow > ( 'Interactive Window' ) ;
73
76
const documentManager = new MockDocumentManager ( ) ;
74
77
const statusProvider = new MockStatusProvider ( ) ;
75
78
const commandManager = new MockCommandManager ( ) ;
79
+ let notebookEditorProvider : INotebookEditorProvider ;
76
80
const server = createTypeMoq < INotebookServer > ( 'jupyter server' ) ;
77
81
let lastFileContents : any ;
78
82
79
- suiteSetup ( ( ) => {
80
- vscodeMocks . initialize ( ) ;
81
- } ) ;
82
- suiteTeardown ( ( ) => {
83
- noop ( ) ;
84
- } ) ;
85
-
86
- setup ( ( ) => {
87
- noop ( ) ;
88
- } ) ;
89
-
90
83
teardown ( ( ) => {
91
84
documentManager . activeTextEditor = undefined ;
92
85
lastFileContents = undefined ;
@@ -111,6 +104,10 @@ suite('Interactive window command listener', async () => {
111
104
}
112
105
113
106
function createCommandListener ( ) : InteractiveWindowCommandListener {
107
+ notebookEditorProvider = mock ( NativeEditorProvider ) ;
108
+ jupyterExecution = mock ( JupyterExecutionFactory ) ;
109
+ applicationShell = mock ( ApplicationShell ) ;
110
+
114
111
// Setup defaults
115
112
when ( interpreterService . onDidChangeInterpreter ) . thenReturn ( dummyEvent . event ) ;
116
113
when ( interpreterService . getInterpreterDetails ( argThat ( o => ! o . includes || ! o . includes ( 'python' ) ) ) ) . thenReject ( 'Unknown interpreter' ) ;
@@ -190,9 +187,7 @@ suite('Interactive window command listener', async () => {
190
187
}
191
188
) ;
192
189
193
- if ( jupyterExecution . isNotebookSupported ) {
194
- when ( jupyterExecution . isNotebookSupported ( ) ) . thenResolve ( true ) ;
195
- }
190
+ when ( jupyterExecution . isNotebookSupported ( ) ) . thenResolve ( true ) ;
196
191
197
192
documentManager . addDocument ( '#%%\r\nprint("code")' , 'bar.ipynb' ) ;
198
193
@@ -211,7 +206,8 @@ suite('Interactive window command listener', async () => {
211
206
instance ( configService ) ,
212
207
statusProvider ,
213
208
instance ( notebookImporter ) ,
214
- instance ( dataScienceErrorHandler ) ) ;
209
+ instance ( dataScienceErrorHandler ) ,
210
+ instance ( notebookEditorProvider ) ) ;
215
211
result . register ( commandManager ) ;
216
212
217
213
return result ;
@@ -233,9 +229,14 @@ suite('Interactive window command listener', async () => {
233
229
const doc = await documentManager . openTextDocument ( 'bar.ipynb' ) ;
234
230
await documentManager . showTextDocument ( doc ) ;
235
231
when ( applicationShell . showSaveDialog ( argThat ( o => o . saveLabel && o . saveLabel . includes ( 'Export' ) ) ) ) . thenReturn ( Promise . resolve ( Uri . file ( 'foo' ) ) ) ;
232
+ when ( applicationShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( 'moo' ) ) ;
233
+ when ( applicationShell . showInformationMessage ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( 'moo' ) ) ;
234
+ when ( jupyterExecution . isSpawnSupported ( ) ) . thenResolve ( true ) ;
236
235
237
236
await commandManager . executeCommand ( Commands . ExportFileAsNotebook , Uri . file ( 'bar.ipynb' ) , undefined ) ;
237
+
238
238
assert . ok ( lastFileContents , 'Export file was not written to' ) ;
239
+ verify ( applicationShell . showInformationMessage ( anything ( ) , localize . DataScience . exportOpenQuestion1 ( ) , localize . DataScience . exportOpenQuestion ( ) ) ) . once ( ) ;
239
240
} ) ;
240
241
test ( 'Export File and output' , async ( ) => {
241
242
createCommandListener ( ) ;
@@ -250,9 +251,13 @@ suite('Interactive window command listener', async () => {
250
251
251
252
when ( applicationShell . showSaveDialog ( argThat ( o => o . saveLabel && o . saveLabel . includes ( 'Export' ) ) ) ) . thenReturn ( Promise . resolve ( Uri . file ( 'foo' ) ) ) ;
252
253
when ( applicationShell . showInformationMessage ( anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( 'moo' ) ) ;
254
+ when ( applicationShell . showInformationMessage ( anything ( ) , anything ( ) , anything ( ) ) ) . thenReturn ( Promise . resolve ( 'moo' ) ) ;
255
+ when ( jupyterExecution . isSpawnSupported ( ) ) . thenResolve ( true ) ;
253
256
254
257
await commandManager . executeCommand ( Commands . ExportFileAndOutputAsNotebook , Uri . file ( 'bar.ipynb' ) ) ;
258
+
255
259
assert . ok ( lastFileContents , 'Export file was not written to' ) ;
260
+ verify ( applicationShell . showInformationMessage ( anything ( ) , localize . DataScience . exportOpenQuestion1 ( ) , localize . DataScience . exportOpenQuestion ( ) ) ) . once ( ) ;
256
261
} ) ;
257
262
test ( 'Export skipped on no file' , async ( ) => {
258
263
createCommandListener ( ) ;
@@ -268,5 +273,4 @@ suite('Interactive window command listener', async () => {
268
273
await commandManager . executeCommand ( Commands . ExportFileAsNotebook , undefined , undefined ) ;
269
274
assert . ok ( lastFileContents , 'Export file was not written to' ) ;
270
275
} ) ;
271
-
272
276
} ) ;
0 commit comments