|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { instance, mock, when } from 'ts-mockito'; |
| 8 | +import { Uri } from 'vscode'; |
| 9 | +import { PythonSettings } from '../../../client/common/configSettings'; |
| 10 | +import { ConfigurationService } from '../../../client/common/configuration/service'; |
| 11 | +import { CondaInstaller } from '../../../client/common/installer/condaInstaller'; |
| 12 | +import { IConfigurationService, IPythonSettings } from '../../../client/common/types'; |
| 13 | +import { ICondaService } from '../../../client/interpreter/contracts'; |
| 14 | +import { CondaService } from '../../../client/interpreter/locators/services/condaService'; |
| 15 | +import { ServiceContainer } from '../../../client/ioc/container'; |
| 16 | +import { IServiceContainer } from '../../../client/ioc/types'; |
| 17 | + |
| 18 | +suite('Common - Conda Installer', () => { |
| 19 | + let installer: CondaInstaller; |
| 20 | + let serviceContainer: IServiceContainer; |
| 21 | + let condaService: ICondaService; |
| 22 | + let configService: IConfigurationService; |
| 23 | + setup(() => { |
| 24 | + serviceContainer = mock(ServiceContainer); |
| 25 | + condaService = mock(CondaService); |
| 26 | + configService = mock(ConfigurationService); |
| 27 | + when(serviceContainer.get<ICondaService>(ICondaService)).thenReturn(instance(condaService)); |
| 28 | + when(serviceContainer.get<IConfigurationService>(IConfigurationService)).thenReturn(instance(configService)); |
| 29 | + installer = new CondaInstaller(instance(serviceContainer)); |
| 30 | + }); |
| 31 | + test('Name and priority', async () => { |
| 32 | + assert.equal(installer.displayName, 'Conda'); |
| 33 | + assert.equal(installer.priority, 0); |
| 34 | + }); |
| 35 | + test('Installer is not supported when conda is not available', async () => { |
| 36 | + const uri = Uri.file(__filename); |
| 37 | + when(condaService.isCondaAvailable()).thenResolve(false); |
| 38 | + |
| 39 | + const supported = await installer.isSupported(uri); |
| 40 | + |
| 41 | + assert.equal(supported, false); |
| 42 | + }); |
| 43 | + test('Installer is not supported when current env is not a conda env', async () => { |
| 44 | + const uri = Uri.file(__filename); |
| 45 | + const settings: IPythonSettings = mock(PythonSettings); |
| 46 | + const pythonPath = 'my py path'; |
| 47 | + |
| 48 | + when(settings.pythonPath).thenReturn(pythonPath); |
| 49 | + when(condaService.isCondaAvailable()).thenResolve(true); |
| 50 | + when(configService.getSettings(uri)).thenReturn(instance(settings)); |
| 51 | + when(condaService.isCondaEnvironment(pythonPath)).thenResolve(false); |
| 52 | + |
| 53 | + const supported = await installer.isSupported(uri); |
| 54 | + |
| 55 | + assert.equal(supported, false); |
| 56 | + }); |
| 57 | + test('Installer is supported when current env is a conda env', async () => { |
| 58 | + const uri = Uri.file(__filename); |
| 59 | + const settings: IPythonSettings = mock(PythonSettings); |
| 60 | + const pythonPath = 'my py path'; |
| 61 | + |
| 62 | + when(settings.pythonPath).thenReturn(pythonPath); |
| 63 | + when(condaService.isCondaAvailable()).thenResolve(true); |
| 64 | + when(configService.getSettings(uri)).thenReturn(instance(settings)); |
| 65 | + when(condaService.isCondaEnvironment(pythonPath)).thenResolve(true); |
| 66 | + |
| 67 | + const supported = await installer.isSupported(uri); |
| 68 | + |
| 69 | + assert.equal(supported, true); |
| 70 | + }); |
| 71 | +}); |
0 commit comments