Skip to content

Commit

Permalink
uncomment my code
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Feb 3, 2025
1 parent eb3122d commit 7b4fb2a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
16 changes: 8 additions & 8 deletions src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useEnvExtension } from '../../envExt/api.internal';
import { ensureTerminalLegacy } from '../../envExt/api.legacy';
import { sleep } from '../utils/async';
import { isWindows } from '../utils/platform';
// import { getPythonMinorVersion } from '../../repl/replUtils';
import { getPythonMinorVersion } from '../../repl/replUtils';

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

// const minorVersion = this.options?.resource
// ? await getPythonMinorVersion(
// this.options.resource,
// this.serviceContainer.get<IInterpreterService>(IInterpreterService),
// )
// : undefined;
// || (minorVersion ?? 0) >= 13
const minorVersion = this.options?.resource
? await getPythonMinorVersion(
this.options.resource,
this.serviceContainer.get<IInterpreterService>(IInterpreterService),
)
: undefined;
|| (minorVersion ?? 0) >= 13

if ((isPythonShell && !pythonrcSetting) || (isPythonShell && isWindows())) {
// If user has explicitly disabled SI for Python, use sendText for inside Terminal REPL.
Expand Down
122 changes: 61 additions & 61 deletions src/test/common/terminals/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TerminalShellExecution,
TerminalShellExecutionEndEvent,
TerminalShellIntegration,
// Uri,
Uri,
Terminal as VSCodeTerminal,
WorkspaceConfiguration,
} from 'vscode';
Expand All @@ -22,7 +22,7 @@ import { TerminalService } from '../../../client/common/terminal/service';
import {
ITerminalActivator,
ITerminalHelper,
// TerminalCreationOptions,
TerminalCreationOptions,
TerminalShellType,
} from '../../../client/common/terminal/types';
import { IDisposableRegistry } from '../../../client/common/types';
Expand All @@ -33,7 +33,7 @@ import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis'
import * as platform from '../../../client/common/utils/platform';
import * as extapi from '../../../client/envExt/api.internal';
import { IInterpreterService } from '../../../client/interpreter/contracts';
// import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';

suite('Terminal Service', () => {
let service: TerminalService;
Expand All @@ -55,7 +55,7 @@ suite('Terminal Service', () => {
let isWindowsStub: sinon.SinonStub;
let useEnvExtensionStub: sinon.SinonStub;
let interpreterService: TypeMoq.IMock<IInterpreterService>;
// let options: TypeMoq.IMock<TerminalCreationOptions>;
let options: TypeMoq.IMock<TerminalCreationOptions>;

setup(() => {
useEnvExtensionStub = sinon.stub(extapi, 'useEnvExtension');
Expand Down Expand Up @@ -102,13 +102,13 @@ suite('Terminal Service', () => {
disposables = [];

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

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

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

// test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python < 3.13', async () => {
// isWindowsStub.returns(false);
// pythonConfig
// .setup((p) => p.get('terminal.shellIntegration.enabled'))
// .returns(() => true)
// .verifiable(TypeMoq.Times.once());

// terminalHelper
// .setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
// .returns(() => Promise.resolve(undefined));
// service = new TerminalService(mockServiceContainer.object);
// const textToSend = 'Some Text';
// terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
// terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);

// service.ensureTerminal();
// service.executeCommand(textToSend, true);

// terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
// terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
// });

// test('Ensure sendText is called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python >= 3.13', async () => {
// interpreterService.reset();

// interpreterService
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
// .returns(() =>
// Promise.resolve({ path: 'yo', version: { major: 3, minor: 13, patch: 0 } } as PythonEnvironment),
// );

// isWindowsStub.returns(false);
// pythonConfig
// .setup((p) => p.get('terminal.shellIntegration.enabled'))
// .returns(() => true)
// .verifiable(TypeMoq.Times.once());

// terminalHelper
// .setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
// .returns(() => Promise.resolve(undefined));

// service = new TerminalService(mockServiceContainer.object, options.object);
// const textToSend = 'Some Text';
// terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
// terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);

// await service.ensureTerminal();
// await service.executeCommand(textToSend, true);

// terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.once());
// });
test('Ensure sendText is NOT called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python < 3.13', async () => {
isWindowsStub.returns(false);
pythonConfig
.setup((p) => p.get('terminal.shellIntegration.enabled'))
.returns(() => true)
.verifiable(TypeMoq.Times.once());

terminalHelper
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(undefined));
service = new TerminalService(mockServiceContainer.object);
const textToSend = 'Some Text';
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);

service.ensureTerminal();
service.executeCommand(textToSend, true);

terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.never());
});

test('Ensure sendText is called when Python shell integration and terminal shell integration are both enabled - Mac, Linux && Python >= 3.13', async () => {
interpreterService.reset();

interpreterService
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny()))
.returns(() =>
Promise.resolve({ path: 'yo', version: { major: 3, minor: 13, patch: 0 } } as PythonEnvironment),
);

isWindowsStub.returns(false);
pythonConfig
.setup((p) => p.get('terminal.shellIntegration.enabled'))
.returns(() => true)
.verifiable(TypeMoq.Times.once());

terminalHelper
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(undefined));

service = new TerminalService(mockServiceContainer.object, options.object);
const textToSend = 'Some Text';
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);

await service.ensureTerminal();
await service.executeCommand(textToSend, true);

terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.once());
});

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

0 comments on commit 7b4fb2a

Please sign in to comment.