@@ -43,6 +43,12 @@ const info: PythonEnvironment = {
43
43
sysVersion : '' ,
44
44
} ;
45
45
46
+ const interpreter : PythonEnvironment = {
47
+ ...info ,
48
+ envType : EnvironmentType . Unknown ,
49
+ path : PYTHON_PATH ,
50
+ } ;
51
+
46
52
suite ( 'TensorBoard session creation' , async ( ) => {
47
53
let serviceManager : IServiceManager ;
48
54
let errorMessageStub : Sinon . SinonStub ;
@@ -67,12 +73,6 @@ suite('TensorBoard session creation', async () => {
67
73
sandbox . stub ( ExperimentHelpers , 'inDiscoveryExperiment' ) . resolves ( false ) ;
68
74
experimentService = serviceManager . get < IExperimentService > ( IExperimentService ) ;
69
75
70
- // Ensure we use CI Python
71
- const interpreter : PythonEnvironment = {
72
- ...info ,
73
- envType : EnvironmentType . Unknown ,
74
- path : PYTHON_PATH ,
75
- } ;
76
76
const interpreterService = serviceManager . get < IInterpreterService > ( IInterpreterService ) ;
77
77
sandbox . stub ( interpreterService , 'getActiveInterpreter' ) . resolves ( interpreter ) ;
78
78
@@ -94,16 +94,21 @@ suite('TensorBoard session creation', async () => {
94
94
isInTorchProfilerExperiment : boolean ,
95
95
hasTorchImports : boolean ,
96
96
tensorBoardInstallStatus : ProductInstallStatus ,
97
- isTorchProfilerPackageInstalled : boolean ,
97
+ torchProfilerPackageInstallStatus : ProductInstallStatus ,
98
98
installPromptSelection : 'Yes' | 'No' ,
99
99
) {
100
100
sandbox
101
101
. stub ( experimentService , 'inExperiment' )
102
102
. withArgs ( TorchProfiler . experiment )
103
103
. resolves ( isInTorchProfilerExperiment ) ;
104
104
sandbox . stub ( ImportTracker , 'hasModuleImport' ) . withArgs ( 'torch' ) . returns ( hasTorchImports ) ;
105
- sandbox . stub ( installer , 'isProductVersionCompatible' ) . resolves ( tensorBoardInstallStatus ) ;
106
- sandbox . stub ( installer , 'isInstalled' ) . resolves ( isTorchProfilerPackageInstalled ) ;
105
+ const isProductVersionCompatible = sandbox . stub ( installer , 'isProductVersionCompatible' ) ;
106
+ isProductVersionCompatible
107
+ . withArgs ( Product . tensorboard , '>= 2.4.1' , interpreter )
108
+ . resolves ( tensorBoardInstallStatus ) ;
109
+ isProductVersionCompatible
110
+ . withArgs ( Product . torchProfilerImportName , '>= 0.2.0' , interpreter )
111
+ . resolves ( torchProfilerPackageInstallStatus ) ;
107
112
errorMessageStub = sandbox . stub ( applicationShell , 'showErrorMessage' ) ;
108
113
errorMessageStub . resolves ( installPromptSelection ) ;
109
114
}
@@ -170,7 +175,7 @@ suite('TensorBoard session creation', async () => {
170
175
async function runTest ( expectTensorBoardUpgrade : boolean ) {
171
176
const installStub = sandbox . stub ( installer , 'install' ) . resolves ( InstallerResponse . Installed ) ;
172
177
await createSessionAndVerifyMessage ( TensorBoard . installTensorBoardAndProfilerPluginPrompt ( ) ) ;
173
- assert . ok ( installStub . calledTwice , 'Did not install anything' ) ;
178
+ assert . ok ( installStub . calledTwice , `Expected 2 installs but got ${ installStub . callCount } calls` ) ;
174
179
assert . ok ( installStub . calledWith ( Product . torchProfilerInstallName ) ) ;
175
180
assert . ok (
176
181
installStub . calledWith (
@@ -182,17 +187,17 @@ suite('TensorBoard session creation', async () => {
182
187
) ;
183
188
}
184
189
test ( 'In experiment: true, has torch imports: true, is profiler package installed: false, TensorBoard needs upgrade' , async ( ) => {
185
- configureStubs ( true , true , ProductInstallStatus . NeedsUpgrade , false , 'Yes' ) ;
190
+ configureStubs ( true , true , ProductInstallStatus . NeedsUpgrade , ProductInstallStatus . NotInstalled , 'Yes' ) ;
186
191
await runTest ( true ) ;
187
192
} ) ;
188
193
test ( 'In experiment: true, has torch imports: true, is profiler package installed: false, TensorBoard not installed' , async ( ) => {
189
- configureStubs ( true , true , ProductInstallStatus . NotInstalled , false , 'Yes' ) ;
194
+ configureStubs ( true , true , ProductInstallStatus . NotInstalled , ProductInstallStatus . NotInstalled , 'Yes' ) ;
190
195
await runTest ( false ) ;
191
196
} ) ;
192
197
} ) ;
193
198
suite ( 'Install profiler only' , async ( ) => {
194
199
test ( 'In experiment: true, has torch imports: true, is profiler package installed: false, TensorBoard installed' , async ( ) => {
195
- configureStubs ( true , true , ProductInstallStatus . Installed , false , 'Yes' ) ;
200
+ configureStubs ( true , true , ProductInstallStatus . Installed , ProductInstallStatus . NotInstalled , 'Yes' ) ;
196
201
sandbox
197
202
. stub ( applicationShell , 'showQuickPick' )
198
203
. resolves ( { label : TensorBoard . useCurrentWorkingDirectory ( ) } ) ;
@@ -222,14 +227,20 @@ suite('TensorBoard session creation', async () => {
222
227
suite ( 'Install tensorboard only' , async ( ) => {
223
228
[ false , true ] . forEach ( async ( inExperiment ) => {
224
229
[ false , true ] . forEach ( async ( hasTorchImports ) => {
225
- [ false , true ] . forEach ( async ( isTorchProfilerPackageInstalled ) => {
230
+ [
231
+ ProductInstallStatus . Installed ,
232
+ ProductInstallStatus . NotInstalled ,
233
+ ProductInstallStatus . NeedsUpgrade ,
234
+ ] . forEach ( async ( torchProfilerInstallStatus ) => {
235
+ const isTorchProfilerPackageInstalled =
236
+ torchProfilerInstallStatus === ProductInstallStatus . Installed ;
226
237
if ( ! ( inExperiment && hasTorchImports && ! isTorchProfilerPackageInstalled ) ) {
227
238
test ( `In experiment: ${ inExperiment } , has torch imports: ${ hasTorchImports } , is profiler package installed: ${ isTorchProfilerPackageInstalled } , TensorBoard not installed` , async ( ) => {
228
239
configureStubs (
229
240
inExperiment ,
230
241
hasTorchImports ,
231
242
ProductInstallStatus . NotInstalled ,
232
- isTorchProfilerPackageInstalled ,
243
+ torchProfilerInstallStatus ,
233
244
'No' ,
234
245
) ;
235
246
await createSessionAndVerifyMessage ( TensorBoard . installPrompt ( ) ) ;
@@ -244,7 +255,7 @@ suite('TensorBoard session creation', async () => {
244
255
const installStub = sandbox . stub ( installer , 'install' ) . resolves ( InstallerResponse . Installed ) ;
245
256
await createSessionAndVerifyMessage ( TensorBoard . upgradePrompt ( ) ) ;
246
257
247
- assert . ok ( installStub . calledOnce , 'Did not install anything' ) ;
258
+ assert . ok ( installStub . calledOnce , `Expected 1 install but got ${ installStub . callCount } installs` ) ;
248
259
assert . ok ( installStub . args [ 0 ] [ 0 ] === Product . tensorboard , 'Did not install tensorboard' ) ;
249
260
assert . ok (
250
261
installStub . args . filter ( ( argsList ) => argsList [ 0 ] === Product . torchProfilerInstallName ) . length ===
@@ -254,14 +265,20 @@ suite('TensorBoard session creation', async () => {
254
265
}
255
266
[ false , true ] . forEach ( async ( inExperiment ) => {
256
267
[ false , true ] . forEach ( async ( hasTorchImports ) => {
257
- [ false , true ] . forEach ( async ( isTorchProfilerPackageInstalled ) => {
268
+ [
269
+ ProductInstallStatus . Installed ,
270
+ ProductInstallStatus . NotInstalled ,
271
+ ProductInstallStatus . NeedsUpgrade ,
272
+ ] . forEach ( async ( torchProfilerInstallStatus ) => {
273
+ const isTorchProfilerPackageInstalled =
274
+ torchProfilerInstallStatus === ProductInstallStatus . Installed ;
258
275
if ( ! ( inExperiment && hasTorchImports && ! isTorchProfilerPackageInstalled ) ) {
259
276
test ( `In experiment: ${ inExperiment } , has torch imports: ${ hasTorchImports } , is profiler package installed: ${ isTorchProfilerPackageInstalled } , TensorBoard needs upgrade` , async ( ) => {
260
277
configureStubs (
261
278
inExperiment ,
262
279
hasTorchImports ,
263
280
ProductInstallStatus . NeedsUpgrade ,
264
- isTorchProfilerPackageInstalled ,
281
+ torchProfilerInstallStatus ,
265
282
'Yes' ,
266
283
) ;
267
284
await runTest ( ) ;
@@ -285,14 +302,20 @@ suite('TensorBoard session creation', async () => {
285
302
}
286
303
[ false , true ] . forEach ( async ( inExperiment ) => {
287
304
[ false , true ] . forEach ( async ( hasTorchImports ) => {
288
- [ false , true ] . forEach ( async ( isTorchProfilerPackageInstalled ) => {
305
+ [
306
+ ProductInstallStatus . Installed ,
307
+ ProductInstallStatus . NotInstalled ,
308
+ ProductInstallStatus . NeedsUpgrade ,
309
+ ] . forEach ( async ( torchProfilerInstallStatus ) => {
310
+ const isTorchProfilerPackageInstalled =
311
+ torchProfilerInstallStatus === ProductInstallStatus . Installed ;
289
312
if ( ! ( inExperiment && hasTorchImports && ! isTorchProfilerPackageInstalled ) ) {
290
313
test ( `In experiment: ${ inExperiment } , has torch imports: ${ hasTorchImports } , is profiler package installed: ${ isTorchProfilerPackageInstalled } , TensorBoard installed` , async ( ) => {
291
314
configureStubs (
292
315
inExperiment ,
293
316
hasTorchImports ,
294
317
ProductInstallStatus . Installed ,
295
- isTorchProfilerPackageInstalled ,
318
+ torchProfilerInstallStatus ,
296
319
'Yes' ,
297
320
) ;
298
321
await runTest ( ) ;
@@ -335,7 +358,7 @@ suite('TensorBoard session creation', async () => {
335
358
assert . ok ( quickPickStub . notCalled , 'User opted not to upgrade and we proceeded to create session' ) ;
336
359
} ) ;
337
360
test ( 'If TensorBoard is not installed and user chooses not to install, do not show error' , async ( ) => {
338
- configureStubs ( true , true , ProductInstallStatus . NotInstalled , false , 'Yes' ) ;
361
+ configureStubs ( true , true , ProductInstallStatus . NotInstalled , ProductInstallStatus . NotInstalled , 'Yes' ) ;
339
362
sandbox . stub ( installer , 'install' ) . resolves ( InstallerResponse . Ignore ) ;
340
363
341
364
await commandManager . executeCommand (
@@ -385,7 +408,7 @@ suite('TensorBoard session creation', async () => {
385
408
assert . ok ( errorMessageStub . called , 'TensorBoard timed out but no error was shown' ) ;
386
409
} ) ;
387
410
test ( 'If installing the profiler package fails, do not show error, continue to create session' , async ( ) => {
388
- configureStubs ( true , true , ProductInstallStatus . Installed , false , 'Yes' ) ;
411
+ configureStubs ( true , true , ProductInstallStatus . Installed , ProductInstallStatus . NotInstalled , 'Yes' ) ;
389
412
sandbox
390
413
. stub ( applicationShell , 'showQuickPick' )
391
414
. resolves ( { label : TensorBoard . useCurrentWorkingDirectory ( ) } ) ;
@@ -404,7 +427,7 @@ suite('TensorBoard session creation', async () => {
404
427
assert . ok ( session . panel ?. visible , 'Webview panel not shown, expected successful session creation' ) ;
405
428
} ) ;
406
429
test ( 'If user opts not to install profiler package and tensorboard is already installed, continue to create session' , async ( ) => {
407
- configureStubs ( true , true , ProductInstallStatus . Installed , false , 'No' ) ;
430
+ configureStubs ( true , true , ProductInstallStatus . Installed , ProductInstallStatus . NotInstalled , 'No' ) ;
408
431
sandbox
409
432
. stub ( applicationShell , 'showQuickPick' )
410
433
. resolves ( { label : TensorBoard . useCurrentWorkingDirectory ( ) } ) ;
0 commit comments