@@ -128,11 +128,18 @@ suite('DataScience notebook tests', () => {
128128 }
129129 }
130130
131- async function verifySimple ( notebook : INotebook | undefined , code : string , expectedValue : any ) : Promise < void > {
131+ async function verifySimple ( notebook : INotebook | undefined , code : string , expectedValue : any , pathVerify = false ) : Promise < void > {
132132 const cells = await notebook ! . execute ( code , path . join ( srcDirectory ( ) , 'foo.py' ) , 2 , uuid ( ) ) ;
133133 assert . equal ( cells . length , 1 , `Wrong number of cells returned` ) ;
134134 const data = extractDataOutput ( cells [ 0 ] ) ;
135- assert . equal ( data , expectedValue , 'Cell value does not match' ) ;
135+ if ( pathVerify ) {
136+ // For a path comparison normalize output and add single quotes on expected value
137+ const normalizedOutput = path . normalize ( data ) . toUpperCase ( ) ;
138+ const normalizedTarget = `'${ path . normalize ( expectedValue ) . toUpperCase ( ) } '` ;
139+ assert . equal ( normalizedOutput , normalizedTarget , 'Cell path values does not match' ) ;
140+ } else {
141+ assert . equal ( data , expectedValue , 'Cell value does not match' ) ;
142+ }
136143 }
137144
138145 async function verifyError ( notebook : INotebook | undefined , code : string , errorString : string ) : Promise < void > {
@@ -224,14 +231,21 @@ suite('DataScience notebook tests', () => {
224231 } ) ;
225232 }
226233
227- async function createNotebook ( useDefaultConfig : boolean , expectFailure ?: boolean , usingDarkTheme ?: boolean , purpose ?: string ) : Promise < INotebook | undefined > {
234+ async function createNotebook ( useDefaultConfig : boolean , expectFailure ?: boolean , usingDarkTheme ?: boolean , purpose ?: string , workingDir ?: string , launchingFile ?: string ) : Promise < INotebook | undefined > {
228235 // Catch exceptions. Throw a specific assertion if the promise fails
229236 try {
230- const server = await jupyterExecution . connectToNotebookServer ( { usingDarkTheme, useDefaultConfig, workingDir : ioc . getSettings ( ) . datascience . notebookFileRoot , purpose : purpose ? purpose : '1' } ) ;
237+ const server = await jupyterExecution . connectToNotebookServer ( { usingDarkTheme, useDefaultConfig, workingDir : workingDir ? workingDir : ioc . getSettings ( ) . datascience . notebookFileRoot , purpose : purpose ? purpose : '1' } ) ;
231238 if ( expectFailure ) {
232239 assert . ok ( false , `Expected server to not be created` ) ;
233240 }
234- return server ? await server . createNotebook ( Uri . parse ( Identifiers . InteractiveWindowIdentity ) ) : undefined ;
241+ if ( server ) {
242+ const notebook = await server . createNotebook ( Uri . parse ( Identifiers . InteractiveWindowIdentity ) ) ;
243+ // If specified set our launch file
244+ if ( launchingFile ) {
245+ await notebook . setLaunchingFile ( launchingFile ) ;
246+ }
247+ return notebook ;
248+ }
235249 } catch ( exc ) {
236250 if ( ! expectFailure ) {
237251 assert . ok ( false , `Expected server to be created, but got ${ exc } ` ) ;
@@ -249,6 +263,12 @@ suite('DataScience notebook tests', () => {
249263 }
250264 }
251265
266+ function changeMockWorkingDirectory ( workingDir : string ) {
267+ if ( ioc . mockJupyter ) {
268+ ioc . mockJupyter . changeWorkingDirectory ( workingDir ) ;
269+ }
270+ }
271+
252272 function addInterruptableMockData ( code : string , resultGenerator : ( c : CancellationToken ) => Promise < { result : string ; haveMore : boolean } > ) {
253273 if ( ioc . mockJupyter ) {
254274 ioc . mockJupyter . addContinuousOutputCell ( code , resultGenerator ) ;
@@ -531,9 +551,18 @@ suite('DataScience notebook tests', () => {
531551 }
532552 } ) ;
533553
534- runTest ( 'Verify path' , async ( ) => {
535- const notebook = await createNotebook ( true ) ;
536- await verifySimple ( notebook , 'import os\nos.getcwd()' , EXTENSION_ROOT_DIR ) ;
554+ runTest ( 'Verify manual working directory' , async ( ) => {
555+ // Instead of default, manually set a working directory
556+ const notebook = await createNotebook ( true , undefined , undefined , undefined , EXTENSION_ROOT_DIR ) ;
557+ await verifySimple ( notebook , 'import os\nos.getcwd()' , EXTENSION_ROOT_DIR , true ) ;
558+ } ) ;
559+
560+ // tslint:disable-next-line:no-invalid-template-strings
561+ runTest ( 'Verify ${fileDirname} working directory' , async ( ) => {
562+ // Verify that the default ${fileDirname} setting sets the working directory to the file path
563+ changeMockWorkingDirectory ( `'${ srcDirectory ( ) } '` ) ;
564+ const notebook = await createNotebook ( true , undefined , undefined , undefined , undefined , path . join ( srcDirectory ( ) , 'foo.py' ) ) ;
565+ await verifySimple ( notebook , 'import os\nos.getcwd()' , srcDirectory ( ) , true ) ;
537566 } ) ;
538567
539568 runTest ( 'Change Interpreter' , async ( ) => {
0 commit comments