From 05ad30e22a87e208bf2ffe8dc661ed6ff4d7421b Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 15 Mar 2018 09:47:59 -0700 Subject: [PATCH] Ensure conda installer is not used for non-conda environments (#1065) * :bug: ensure conda install is not used for non conda environments * :white_check_mark: add test * :memo: change log * Fixes #969 --- news/2 Fixes/969.md | 1 + src/client/common/installer/condaInstaller.ts | 4 ++-- src/test/common/moduleInstaller.test.ts | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 news/2 Fixes/969.md diff --git a/news/2 Fixes/969.md b/news/2 Fixes/969.md new file mode 100644 index 000000000000..a991de1a919d --- /dev/null +++ b/news/2 Fixes/969.md @@ -0,0 +1 @@ +Ensure conda installer is not used for non-conda environments. diff --git a/src/client/common/installer/condaInstaller.ts b/src/client/common/installer/condaInstaller.ts index a4802817b8d9..10acd9f3bb64 100644 --- a/src/client/common/installer/condaInstaller.ts +++ b/src/client/common/installer/condaInstaller.ts @@ -30,8 +30,8 @@ export class CondaInstaller extends ModuleInstaller implements IModuleInstaller * @returns {Promise} Whether conda is supported as a module installer or not. */ public async isSupported(resource?: Uri): Promise { - if (this.isCondaAvailable !== undefined) { - return this.isCondaAvailable!; + if (this.isCondaAvailable === false) { + return false; } const condaLocator = this.serviceContainer.get(ICondaService); this.isCondaAvailable = await condaLocator.isCondaAvailable(); diff --git a/src/test/common/moduleInstaller.test.ts b/src/test/common/moduleInstaller.test.ts index 768d37afc19f..42e83eb93524 100644 --- a/src/test/common/moduleInstaller.test.ts +++ b/src/test/common/moduleInstaller.test.ts @@ -167,6 +167,22 @@ suite('Module Installer', () => { const condaInstaller = new CondaInstaller(serviceContainer.object); await expect(condaInstaller.isSupported()).to.eventually.equal(true, 'Conda is not supported'); }); + test('Ensure conda is not supported even if conda is available', async () => { + const serviceContainer = TypeMoq.Mock.ofType(); + + const configService = TypeMoq.Mock.ofType(); + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService))).returns(() => configService.object); + const settings = TypeMoq.Mock.ofType(); + const pythonPath = 'pythonABC'; + settings.setup(s => s.pythonPath).returns(() => pythonPath); + configService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ICondaService))).returns(() => condaService.object); + condaService.setup(c => c.isCondaAvailable()).returns(() => Promise.resolve(true)); + condaService.setup(c => c.isCondaEnvironment(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve(false)); + + const condaInstaller = new CondaInstaller(serviceContainer.object); + await expect(condaInstaller.isSupported()).to.eventually.equal(false, 'Conda should not be supported'); + }); test('Validate pip install arguments', async () => { const interpreterPath = await getCurrentPythonPath();