5
5
6
6
import * as chaiAsPromised from 'chai-as-promised' ;
7
7
import * as path from 'path' ;
8
+ import * as TypeMoq from 'typemoq' ;
8
9
import * as sinon from 'sinon' ;
9
10
import { use , expect } from 'chai' ;
10
11
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants' ;
11
12
import { PythonInlineValueProvider } from '../../../extension/debugger/inlineValue/pythonInlineValueProvider' ;
12
- import { workspace , Range , InlineValueContext } from 'vscode' ;
13
+ import { workspace , Range , InlineValueContext , WorkspaceConfiguration } from 'vscode' ;
13
14
import * as vscodeapi from '../../../extension/common/vscodeapi' ;
14
15
15
16
use ( chaiAsPromised ) ;
@@ -18,16 +19,27 @@ const WS_ROOT = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test');
18
19
19
20
suite ( 'Debugging - pythonInlineProvider' , ( ) => {
20
21
let customRequestStub : sinon . SinonStub ;
22
+ let getConfigurationStub : sinon . SinonStub ;
21
23
22
24
setup ( ( ) => {
23
25
customRequestStub = sinon . stub ( vscodeapi , 'customRequest' ) ;
24
26
customRequestStub . withArgs ( 'scopes' , sinon . match . any ) . resolves ( { scopes : [ { variablesReference : 0 } ] } ) ;
27
+ getConfigurationStub = sinon . stub ( vscodeapi , 'getConfiguration' ) ;
28
+ getConfigurationStub . withArgs ( 'debugpy' ) . returns ( createMoqConfiguration ( true ) ) ;
25
29
} ) ;
26
30
27
31
teardown ( async ( ) => {
28
32
sinon . restore ( ) ;
29
33
} ) ;
30
34
35
+ function createMoqConfiguration ( showPythonInlineValues : boolean ) {
36
+ const debugpySettings = TypeMoq . Mock . ofType < WorkspaceConfiguration > ( ) ;
37
+ debugpySettings
38
+ . setup ( ( p ) => p . get < boolean > ( 'showPythonInlineValues' , TypeMoq . It . isAny ( ) ) )
39
+ . returns ( ( ) => showPythonInlineValues ) ;
40
+ return debugpySettings . object ;
41
+ }
42
+
31
43
test ( 'ProvideInlineValues function should return all the vars in the python file' , async ( ) => {
32
44
customRequestStub . withArgs ( 'variables' , sinon . match . any ) . resolves ( {
33
45
variables : [
@@ -331,7 +343,7 @@ suite('Debugging - pythonInlineProvider', () => {
331
343
expect ( result ) . to . deep . equal ( expected ) ;
332
344
} ) ;
333
345
334
- test . only ( 'ProvideInlineValues function should return all the vars in the python file using Assignment Expressions' , async ( ) => {
346
+ test ( 'ProvideInlineValues function should return all the vars in the python file using Assignment Expressions' , async ( ) => {
335
347
customRequestStub . withArgs ( 'variables' , sinon . match . any ) . resolves ( {
336
348
variables : [
337
349
{
@@ -502,4 +514,16 @@ suite('Debugging - pythonInlineProvider', () => {
502
514
] ;
503
515
expect ( result ) . to . deep . equal ( expected ) ;
504
516
} ) ;
517
+
518
+ test ( "Provider should return empty array if 'showPythonInlineValues' is false" , async ( ) => {
519
+ getConfigurationStub . withArgs ( 'debugpy' ) . returns ( createMoqConfiguration ( false ) ) ;
520
+ const file = path . join ( WS_ROOT , 'pythonFiles' , 'testAssignmentExp.py' ) ;
521
+ let document = await workspace . openTextDocument ( file ) ;
522
+ const viewPort = new Range ( 0 , 0 , 6 , 0 ) ;
523
+ const context = { frameId : 0 , stoppedLocation : new Range ( 3 , 1 , 3 , 1 ) } as InlineValueContext ;
524
+ const inlineValueProvider = new PythonInlineValueProvider ( ) ;
525
+
526
+ const result = await inlineValueProvider . provideInlineValues ( document , viewPort , context ) ;
527
+ expect ( result ) . to . deep . equal ( [ ] ) ;
528
+ } ) ;
505
529
} ) ;
0 commit comments