Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import * as sinon from 'sinon';
import { Disposable, TextDocument, TextEditor, Uri } from 'vscode';
import { Disposable, Terminal, TextDocument, TextEditor, Uri } from 'vscode';

import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
import { Commands } from '../../../client/common/constants';
Expand Down Expand Up @@ -97,6 +97,58 @@ suite('Terminal - Code Execution Manager', () => {
);
});

test('Run Python File passes an unquoted script path to Python Environments', async () => {
useEnvExtensionStub.returns(true);
const commandHandlers = new Map<string, (file: Uri) => Promise<void>>();
commandManager
.setup((c) => c.registerCommand as any)
.returns(() => (command: string, callback: (file: Uri) => Promise<void>) => {
commandHandlers.set(command, callback);
return { dispose: () => void 0 };
});
executionManager.registerCommands();

const helper = TypeMoq.Mock.ofType<ICodeExecutionHelper>();
serviceContainer.setup((s) => s.get(TypeMoq.It.isValue(ICodeExecutionHelper))).returns(() => helper.object);
configService
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
.returns(
() =>
({
terminal: { executeInFileDir: false, launchArgs: ['-I'], focusAfterLaunch: false },
} as IPythonSettings),
);

const terminal = ({ show: sinon.stub() } as unknown) as Terminal;
const runInTerminalStub = sinon.stub(extapi, 'runInTerminal').resolves(terminal);
const runInDedicatedTerminalStub = sinon.stub(extapi, 'runInDedicatedTerminal').resolves(terminal);
for (const command of [
Commands.Exec_In_Terminal,
Commands.Exec_In_Terminal_Icon,
Commands.Exec_In_Separate_Terminal,
]) {
for (const script of [
'with spaces/main.py',
'space and $AUDIT_UNSET.py',
"space and apostrophe's.py",
'space and "quotes".py',
'$(touch marker).py',
]) {
const file = Uri.file(`/workspace/${script}`);
await commandHandlers.get(command)!(file);

const expectedRunner =
command === Commands.Exec_In_Separate_Terminal ? runInDedicatedTerminalStub : runInTerminalStub;
sinon.assert.calledOnceWithExactly(expectedRunner, file, ['-I', file.fsPath], undefined, false);
const otherRunner =
command === Commands.Exec_In_Separate_Terminal ? runInTerminalStub : runInDedicatedTerminalStub;
sinon.assert.notCalled(otherRunner);
runInTerminalStub.resetHistory();
runInDedicatedTerminalStub.resetHistory();
}
}
});

test('Ensure executeFileInterTerminal will do nothing if no file is avialble', async () => {
let commandHandler: undefined | (() => Promise<void>);
commandManager
Expand Down
Loading