Skip to content

Commit 0e5a052

Browse files
committed
try to fix test
1 parent 8580b20 commit 0e5a052

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

src/client/common/terminal/service.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@ export class TerminalService implements ITerminalService, Disposable {
104104
}
105105
const config = getConfiguration('python');
106106
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
107-
108-
const pythonPath = this.serviceContainer
109-
.get<IConfigurationService>(IConfigurationService)
110-
.getSettings(this.options?.resource).pythonPath;
111-
const interpreterInfo =
112-
this.options?.interpreter ||
113-
(await this.serviceContainer
114-
.get<IInterpreterService>(IInterpreterService)
115-
.getInterpreterDetails(pythonPath));
116-
const pythonVersion = interpreterInfo && interpreterInfo.version ? interpreterInfo.version.raw : undefined;
107+
const pythonVersion = await this.getPythonVersion();
117108
const isPython313 = pythonVersion?.startsWith('3.13');
118109

119110
if (isPythonShell && (!pythonrcSetting || isWindows() || isPython313)) {
@@ -191,4 +182,17 @@ export class TerminalService implements ITerminalService, Disposable {
191182
interpreterType,
192183
});
193184
}
185+
186+
private async getPythonVersion(): Promise<string | undefined> {
187+
const pythonPath = this.serviceContainer
188+
.get<IConfigurationService>(IConfigurationService)
189+
.getSettings(this.options?.resource).pythonPath;
190+
const interpreterInfo =
191+
this.options?.interpreter ||
192+
(await this.serviceContainer
193+
.get<IInterpreterService>(IInterpreterService)
194+
.getInterpreterDetails(pythonPath));
195+
const pythonVersion = interpreterInfo && interpreterInfo.version ? interpreterInfo.version.raw : undefined;
196+
return pythonVersion;
197+
}
194198
}

src/test/common/terminals/service.unit.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ import { EXTENSION_ROOT_DIR } from '../../../client/common/constants';
1919
import { IPlatformService } from '../../../client/common/platform/types';
2020
import { TerminalService } from '../../../client/common/terminal/service';
2121
import { ITerminalActivator, ITerminalHelper, TerminalShellType } from '../../../client/common/terminal/types';
22-
import { IDisposableRegistry } from '../../../client/common/types';
22+
import { IConfigurationService, IDisposableRegistry } from '../../../client/common/types';
2323
import { IServiceContainer } from '../../../client/ioc/types';
2424
import { ITerminalAutoActivation } from '../../../client/terminals/types';
2525
import { createPythonInterpreter } from '../../utils/interpreters';
2626
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
2727
import * as platform from '../../../client/common/utils/platform';
28+
import { IInterpreterService } from '../../../client/interpreter/contracts';
29+
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
2830

2931
suite('Terminal Service', () => {
3032
let service: TerminalService;
33+
let configService: TypeMoq.IMock<IConfigurationService>;
34+
let interpreterService: TypeMoq.IMock<IInterpreterService>;
3135
let terminal: TypeMoq.IMock<VSCodeTerminal>;
3236
let terminalManager: TypeMoq.IMock<ITerminalManager>;
3337
let terminalHelper: TypeMoq.IMock<ITerminalHelper>;
@@ -44,8 +48,23 @@ suite('Terminal Service', () => {
4448
let pythonConfig: TypeMoq.IMock<WorkspaceConfiguration>;
4549
let editorConfig: TypeMoq.IMock<WorkspaceConfiguration>;
4650
let isWindowsStub: sinon.SinonStub;
51+
// let getPythonVersionStub: sinon.SinonStub;
4752

4853
setup(() => {
54+
configService = TypeMoq.Mock.ofType<IConfigurationService>();
55+
configService.setup((c) => c.getSettings()).returns(() => ({ pythonPath: 'pythonPath' } as any));
56+
57+
// configService.setup((t) => t.getSettings);
58+
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
59+
// when(interpreterService.getInterpreterDetails(anything())).thenResolve({
60+
// version: { major: 3 },
61+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
62+
// } as any);
63+
64+
interpreterService
65+
.setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny()))
66+
.returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment));
67+
4968
terminal = TypeMoq.Mock.ofType<VSCodeTerminal>();
5069
terminalShellIntegration = TypeMoq.Mock.ofType<TerminalShellIntegration>();
5170
terminal.setup((t) => t.shellIntegration).returns(() => terminalShellIntegration.object);
@@ -95,8 +114,11 @@ suite('Terminal Service', () => {
95114
mockServiceContainer.setup((c) => c.get(IWorkspaceService)).returns(() => workspaceService.object);
96115
mockServiceContainer.setup((c) => c.get(ITerminalActivator)).returns(() => terminalActivator.object);
97116
mockServiceContainer.setup((c) => c.get(ITerminalAutoActivation)).returns(() => terminalAutoActivator.object);
117+
mockServiceContainer.setup((c) => c.get(IConfigurationService)).returns(() => configService.object);
118+
mockServiceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object);
98119
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
99120
isWindowsStub = sinon.stub(platform, 'isWindows');
121+
100122
pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
101123
editorConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
102124
getConfigurationStub.callsFake((section: string) => {
@@ -234,7 +256,7 @@ suite('Terminal Service', () => {
234256
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
235257
});
236258

237-
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux', async () => {
259+
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux : !Python3.13', async () => {
238260
isWindowsStub.returns(false);
239261
pythonConfig
240262
.setup((p) => p.get('terminal.shellIntegration.enabled'))
@@ -256,6 +278,8 @@ suite('Terminal Service', () => {
256278
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
257279
});
258280

281+
// Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux : Python3.13
282+
259283
test('Ensure sendText IS called even when Python shell integration and terminal shell integration are both enabled - Window', async () => {
260284
isWindowsStub.returns(true);
261285
pythonConfig

0 commit comments

Comments
 (0)