From 292e7da12b9e5477addd4d042b7b2f42683a47d0 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 11 Mar 2019 17:05:41 -0700 Subject: [PATCH 1/2] Corrected bug and added tests --- .../condaActivationProvider.ts | 2 +- .../terminals/activation.conda.unit.test.ts | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts index 8f9c4b2459d9..e7b5732b3f97 100644 --- a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts +++ b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts @@ -67,7 +67,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman `source ${activatePath}`; return [ firstActivate, - `conda activate ${envInfo.name}` + `conda activate ${envInfo.name.toCommandArgument()}` ]; } } diff --git a/src/test/common/terminals/activation.conda.unit.test.ts b/src/test/common/terminals/activation.conda.unit.test.ts index b6f70192abf2..d766a41bc650 100644 --- a/src/test/common/terminals/activation.conda.unit.test.ts +++ b/src/test/common/terminals/activation.conda.unit.test.ts @@ -170,6 +170,59 @@ suite('Terminal Environment Activation conda', () => { expect(activationCommands).to.deep.equal(expected, 'Incorrect Activation command'); }); + const interpreterPath = path.join('path', 'to', 'interpreter'); + const environmentName = 'Env'; + const environmentNameHasSpaces = 'Env with spaces'; + const testsForActivationUsingInterpreterPath = + [ + { + testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with no spaces in env name', + envName: environmentName, + expectedResult: ['path/to/activate', 'conda activate Env'], + isWindows: true + }, + { + testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with no spaces in env name', + envName: environmentName, + expectedResult: ['source path/to/activate', 'conda activate Env'], + isWindows: false + }, + { + testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with spaces in env name', + envName: environmentNameHasSpaces, + expectedResult: ['path/to/activate', 'conda activate \"Env with spaces\"'], + isWindows: true + }, + { + testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with spaces in env name', + envName: environmentNameHasSpaces, + expectedResult: ['source path/to/activate', 'conda activate \"Env with spaces\"'], + isWindows: false + } + ]; + + testsForActivationUsingInterpreterPath.forEach((testParams) => { + test(testParams.testName, async () => { + const pythonPath = 'python3'; + platformService.setup(p => p.isWindows).returns(() => testParams.isWindows); + condaService.reset(); + condaService.setup(c => c.getCondaEnvironment(TypeMoq.It.isAny())) + .returns(() => Promise.resolve({ + name: testParams.envName, + path: path.dirname(pythonPath) + })); + condaService.setup(c => c.getCondaVersion()) + .returns(() => Promise.resolve(parse('4.4.0', true)!)); + condaService.setup(c => c.getCondaFileFromInterpreter(TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .returns(() => Promise.resolve(interpreterPath)); + + const provider = new CondaActivationCommandProvider(condaService.object, platformService.object, configService.object); + const activationCommands = await provider.getActivationCommands(undefined, TerminalShellType.bash); + + expect(activationCommands).to.deep.equal(testParams.expectedResult, 'Incorrect Activation command'); + }); + }); + async function expectNoCondaActivationCommandForPowershell(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string, shellType: TerminalShellType, hasSpaceInEnvironmentName = false) { terminalSettings.setup(t => t.activateEnvironment).returns(() => true); platformService.setup(p => p.isLinux).returns(() => isLinux); From 249917d656e048bfa9bd4f973099e2ae4972e6b4 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Mon, 11 Mar 2019 17:05:56 -0700 Subject: [PATCH 2/2] Added news entry --- news/2 Fixes/4243.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/4243.md diff --git a/news/2 Fixes/4243.md b/news/2 Fixes/4243.md new file mode 100644 index 000000000000..32b54fd50125 --- /dev/null +++ b/news/2 Fixes/4243.md @@ -0,0 +1 @@ +Conda activation fails when there is a space in the env name