@@ -13,24 +13,30 @@ import { SemVer } from 'semver';
1313import { anything , instance , mock , verify , when } from 'ts-mockito' ;
1414import { DebugAdapterExecutable , DebugAdapterServer , DebugConfiguration , DebugSession , WorkspaceFolder } from 'vscode' ;
1515import { ConfigurationService } from '../../../../client/common/configuration/service' ;
16- import { IPythonSettings } from '../../../../client/common/types' ;
16+ import { IPersistentStateFactory , IPythonSettings } from '../../../../client/common/types' ;
1717import { Architecture } from '../../../../client/common/utils/platform' ;
1818import { EXTENSION_ROOT_DIR } from '../../../../client/constants' ;
19- import { DebugAdapterDescriptorFactory } from '../../../../client/debugger/extension/adapter/factory' ;
19+ import { DebugAdapterDescriptorFactory , debugStateKeys } from '../../../../client/debugger/extension/adapter/factory' ;
2020import { IDebugAdapterDescriptorFactory } from '../../../../client/debugger/extension/types' ;
2121import { IInterpreterService } from '../../../../client/interpreter/contracts' ;
2222import { InterpreterService } from '../../../../client/interpreter/interpreterService' ;
2323import { EnvironmentType } from '../../../../client/pythonEnvironments/info' ;
2424import { clearTelemetryReporter } from '../../../../client/telemetry' ;
2525import { EventName } from '../../../../client/telemetry/constants' ;
2626import * as windowApis from '../../../../client/common/vscodeApis/windowApis' ;
27+ import { PersistentState , PersistentStateFactory } from '../../../../client/common/persistentState' ;
28+ import { ICommandManager } from '../../../../client/common/application/types' ;
29+ import { CommandManager } from '../../../../client/common/application/commandManager' ;
2730
2831use ( chaiAsPromised ) ;
2932
3033suite ( 'Debugging - Adapter Factory' , ( ) => {
3134 let factory : IDebugAdapterDescriptorFactory ;
3235 let interpreterService : IInterpreterService ;
36+ let stateFactory : IPersistentStateFactory ;
37+ let state : PersistentState < boolean | undefined > ;
3338 let showErrorMessageStub : sinon . SinonStub ;
39+ let commandManager : ICommandManager ;
3440
3541 const nodeExecutable = undefined ;
3642 const debugAdapterPath = path . join ( EXTENSION_ROOT_DIR , 'pythonFiles' , 'lib' , 'python' , 'debugpy' , 'adapter' ) ;
@@ -62,8 +68,16 @@ suite('Debugging - Adapter Factory', () => {
6268 process . env . VSC_PYTHON_CI_TEST = undefined ;
6369 rewiremock . enable ( ) ;
6470 rewiremock ( '@vscode/extension-telemetry' ) . with ( { default : Reporter } ) ;
71+ stateFactory = mock ( PersistentStateFactory ) ;
72+ state = mock ( PersistentState ) as PersistentState < boolean | undefined > ;
73+ commandManager = mock ( CommandManager ) ;
74+
6575 showErrorMessageStub = sinon . stub ( windowApis , 'showErrorMessage' ) ;
6676
77+ when (
78+ stateFactory . createGlobalPersistentState < boolean | undefined > ( debugStateKeys . doNotShowAgain , false ) ,
79+ ) . thenReturn ( instance ( state ) ) ;
80+
6781 const configurationService = mock ( ConfigurationService ) ;
6882 when ( configurationService . getSettings ( undefined ) ) . thenReturn ( ( {
6983 experiments : { enabled : true } ,
@@ -74,7 +88,11 @@ suite('Debugging - Adapter Factory', () => {
7488 when ( interpreterService . getInterpreterDetails ( pythonPath ) ) . thenResolve ( interpreter ) ;
7589 when ( interpreterService . getInterpreters ( anything ( ) ) ) . thenReturn ( [ interpreter ] ) ;
7690
77- factory = new DebugAdapterDescriptorFactory ( instance ( interpreterService ) ) ;
91+ factory = new DebugAdapterDescriptorFactory (
92+ instance ( commandManager ) ,
93+ instance ( interpreterService ) ,
94+ instance ( stateFactory ) ,
95+ ) ;
7896 } ) ;
7997
8098 teardown ( ( ) => {
@@ -138,7 +156,24 @@ suite('Debugging - Adapter Factory', () => {
138156 await expect ( promise ) . to . eventually . be . rejectedWith ( 'Debug Adapter Executable not provided' ) ;
139157 sinon . assert . calledOnce ( showErrorMessageStub ) ;
140158 } ) ;
159+ test ( 'Display a message if python version is less than 3.7' , async ( ) => {
160+ when ( interpreterService . getInterpreters ( anything ( ) ) ) . thenReturn ( [ ] ) ;
161+ const session = createSession ( { } ) ;
162+ const deprecatedInterpreter = {
163+ architecture : Architecture . Unknown ,
164+ path : pythonPath ,
165+ sysPrefix : '' ,
166+ sysVersion : '' ,
167+ envType : EnvironmentType . Unknown ,
168+ version : new SemVer ( '3.6.12-test' ) ,
169+ } ;
170+ when ( state . value ) . thenReturn ( false ) ;
171+ when ( interpreterService . getActiveInterpreter ( anything ( ) ) ) . thenResolve ( deprecatedInterpreter ) ;
141172
173+ await factory . createDebugAdapterDescriptor ( session , nodeExecutable ) ;
174+
175+ sinon . assert . calledOnce ( showErrorMessageStub ) ;
176+ } ) ;
142177 test ( 'Return Debug Adapter server if request is "attach", and port is specified directly' , async ( ) => {
143178 const session = createSession ( { request : 'attach' , port : 5678 , host : 'localhost' } ) ;
144179 const debugServer = new DebugAdapterServer ( session . configuration . port , session . configuration . host ) ;
0 commit comments