Skip to content

Commit

Permalink
Ensure conda installer is not used for non-conda environments (#1065)
Browse files Browse the repository at this point in the history
* 🐛 ensure conda install is not used for non conda environments
* ✅ add test
* 📝 change log
* Fixes #969
  • Loading branch information
DonJayamanne authored Mar 15, 2018
1 parent 3f43da9 commit 05ad30e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/969.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure conda installer is not used for non-conda environments.
4 changes: 2 additions & 2 deletions src/client/common/installer/condaInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class CondaInstaller extends ModuleInstaller implements IModuleInstaller
* @returns {Promise<boolean>} Whether conda is supported as a module installer or not.
*/
public async isSupported(resource?: Uri): Promise<boolean> {
if (this.isCondaAvailable !== undefined) {
return this.isCondaAvailable!;
if (this.isCondaAvailable === false) {
return false;
}
const condaLocator = this.serviceContainer.get<ICondaService>(ICondaService);
this.isCondaAvailable = await condaLocator.isCondaAvailable();
Expand Down
16 changes: 16 additions & 0 deletions src/test/common/moduleInstaller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IServiceContainer>();

const configService = TypeMoq.Mock.ofType<IConfigurationService>();
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService))).returns(() => configService.object);
const settings = TypeMoq.Mock.ofType<IPythonSettings>();
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();
Expand Down

0 comments on commit 05ad30e

Please sign in to comment.