Skip to content

Commit 7b4fb2a

Browse files
committed
uncomment my code
1 parent eb3122d commit 7b4fb2a

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

src/client/common/terminal/service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useEnvExtension } from '../../envExt/api.internal';
2525
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
2626
import { sleep } from '../utils/async';
2727
import { isWindows } from '../utils/platform';
28-
// import { getPythonMinorVersion } from '../../repl/replUtils';
28+
import { getPythonMinorVersion } from '../../repl/replUtils';
2929

3030
@injectable()
3131
export class TerminalService implements ITerminalService, Disposable {
@@ -110,13 +110,13 @@ export class TerminalService implements ITerminalService, Disposable {
110110
const config = getConfiguration('python');
111111
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
112112

113-
// const minorVersion = this.options?.resource
114-
// ? await getPythonMinorVersion(
115-
// this.options.resource,
116-
// this.serviceContainer.get<IInterpreterService>(IInterpreterService),
117-
// )
118-
// : undefined;
119-
// || (minorVersion ?? 0) >= 13
113+
const minorVersion = this.options?.resource
114+
? await getPythonMinorVersion(
115+
this.options.resource,
116+
this.serviceContainer.get<IInterpreterService>(IInterpreterService),
117+
)
118+
: undefined;
119+
|| (minorVersion ?? 0) >= 13
120120

121121
if ((isPythonShell && !pythonrcSetting) || (isPythonShell && isWindows())) {
122122
// If user has explicitly disabled SI for Python, use sendText for inside Terminal REPL.

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

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
TerminalShellExecution,
1212
TerminalShellExecutionEndEvent,
1313
TerminalShellIntegration,
14-
// Uri,
14+
Uri,
1515
Terminal as VSCodeTerminal,
1616
WorkspaceConfiguration,
1717
} from 'vscode';
@@ -22,7 +22,7 @@ import { TerminalService } from '../../../client/common/terminal/service';
2222
import {
2323
ITerminalActivator,
2424
ITerminalHelper,
25-
// TerminalCreationOptions,
25+
TerminalCreationOptions,
2626
TerminalShellType,
2727
} from '../../../client/common/terminal/types';
2828
import { IDisposableRegistry } from '../../../client/common/types';
@@ -33,7 +33,7 @@ import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'
3333
import * as platform from '../../../client/common/utils/platform';
3434
import * as extapi from '../../../client/envExt/api.internal';
3535
import { IInterpreterService } from '../../../client/interpreter/contracts';
36-
// import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
36+
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
3737

3838
suite('Terminal Service', () => {
3939
let service: TerminalService;
@@ -55,7 +55,7 @@ suite('Terminal Service', () => {
5555
let isWindowsStub: sinon.SinonStub;
5656
let useEnvExtensionStub: sinon.SinonStub;
5757
let interpreterService: TypeMoq.IMock<IInterpreterService>;
58-
// let options: TypeMoq.IMock<TerminalCreationOptions>;
58+
let options: TypeMoq.IMock<TerminalCreationOptions>;
5959

6060
setup(() => {
6161
useEnvExtensionStub = sinon.stub(extapi, 'useEnvExtension');
@@ -102,13 +102,13 @@ suite('Terminal Service', () => {
102102
disposables = [];
103103

104104
mockServiceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
105-
// interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
106-
// interpreterService
107-
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
108-
// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment));
105+
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
106+
interpreterService
107+
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
108+
.returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment));
109109

110-
// options = TypeMoq.Mock.ofType<TerminalCreationOptions>();
111-
// options.setup((o) => o.resource).returns(() => Uri.parse('a'));
110+
options = TypeMoq.Mock.ofType<TerminalCreationOptions>();
111+
options.setup((o) => o.resource).returns(() => Uri.parse('a'));
112112

113113
mockServiceContainer.setup((c) => c.get(ITerminalManager)).returns(() => terminalManager.object);
114114
mockServiceContainer.setup((c) => c.get(ITerminalHelper)).returns(() => terminalHelper.object);
@@ -259,57 +259,57 @@ suite('Terminal Service', () => {
259259
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
260260
});
261261

262-
// test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python < 3.13', async () => {
263-
// isWindowsStub.returns(false);
264-
// pythonConfig
265-
// .setup((p) => p.get('terminal.shellIntegration.enabled'))
266-
// .returns(() => true)
267-
// .verifiable(TypeMoq.Times.once());
268-
269-
// terminalHelper
270-
// .setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
271-
// .returns(() => Promise.resolve(undefined));
272-
// service = new TerminalService(mockServiceContainer.object);
273-
// const textToSend = 'Some Text';
274-
// terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
275-
// terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
276-
277-
// service.ensureTerminal();
278-
// service.executeCommand(textToSend, true);
279-
280-
// terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
281-
// terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
282-
// });
283-
284-
// test('Ensure sendText is called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python >= 3.13', async () => {
285-
// interpreterService.reset();
286-
287-
// interpreterService
288-
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
289-
// .returns(() =>
290-
// Promise.resolve({ path: 'yo', version: { major: 3, minor: 13, patch: 0 } } as PythonEnvironment),
291-
// );
292-
293-
// isWindowsStub.returns(false);
294-
// pythonConfig
295-
// .setup((p) => p.get('terminal.shellIntegration.enabled'))
296-
// .returns(() => true)
297-
// .verifiable(TypeMoq.Times.once());
298-
299-
// terminalHelper
300-
// .setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
301-
// .returns(() => Promise.resolve(undefined));
302-
303-
// service = new TerminalService(mockServiceContainer.object, options.object);
304-
// const textToSend = 'Some Text';
305-
// terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
306-
// terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
307-
308-
// await service.ensureTerminal();
309-
// await service.executeCommand(textToSend, true);
310-
311-
// terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.once());
312-
// });
262+
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python < 3.13', async () => {
263+
isWindowsStub.returns(false);
264+
pythonConfig
265+
.setup((p) => p.get('terminal.shellIntegration.enabled'))
266+
.returns(() => true)
267+
.verifiable(TypeMoq.Times.once());
268+
269+
terminalHelper
270+
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
271+
.returns(() => Promise.resolve(undefined));
272+
service = new TerminalService(mockServiceContainer.object);
273+
const textToSend = 'Some Text';
274+
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
275+
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
276+
277+
service.ensureTerminal();
278+
service.executeCommand(textToSend, true);
279+
280+
terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
281+
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
282+
});
283+
284+
test('Ensure sendText is called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python >= 3.13', async () => {
285+
interpreterService.reset();
286+
287+
interpreterService
288+
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
289+
.returns(() =>
290+
Promise.resolve({ path: 'yo', version: { major: 3, minor: 13, patch: 0 } } as PythonEnvironment),
291+
);
292+
293+
isWindowsStub.returns(false);
294+
pythonConfig
295+
.setup((p) => p.get('terminal.shellIntegration.enabled'))
296+
.returns(() => true)
297+
.verifiable(TypeMoq.Times.once());
298+
299+
terminalHelper
300+
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
301+
.returns(() => Promise.resolve(undefined));
302+
303+
service = new TerminalService(mockServiceContainer.object, options.object);
304+
const textToSend = 'Some Text';
305+
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
306+
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);
307+
308+
await service.ensureTerminal();
309+
await service.executeCommand(textToSend, true);
310+
311+
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.once());
312+
});
313313

314314
test('Ensure sendText IS called even when Python shell integration and terminal shell integration are both enabled - Window', async () => {
315315
isWindowsStub.returns(true);

0 commit comments

Comments
 (0)