Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Sep 17, 2018
1 parent d0f17c5 commit bad01ca
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/test/interpreters/condaService.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ suite('Interpreters Conda Service', () => {
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let procServiceFactory: TypeMoq.IMock<IProcessServiceFactory>;
let logger: TypeMoq.IMock<ILogger>;
let condaPath: string;
setup(async () => {
condaPath = '';
logger = TypeMoq.Mock.ofType<ILogger>();
processService = TypeMoq.Mock.ofType<IProcessService>();
platformService = TypeMoq.Mock.ofType<IPlatformService>();
Expand All @@ -60,7 +62,7 @@ suite('Interpreters Conda Service', () => {
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IFileSystem), TypeMoq.It.isAny())).returns(() => fileSystem.object);
serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService), TypeMoq.It.isAny())).returns(() => config.object);
config.setup(c => c.getSettings(TypeMoq.It.isValue(undefined))).returns(() => settings.object);
settings.setup(p => p.condaPath).returns(() => '');
settings.setup(p => p.condaPath).returns(() => condaPath);
condaService = new CondaService(serviceContainer.object, registryInterpreterLocatorService.object);

fileSystem.setup(fs => fs.arePathsSame(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((p1, p2) => {
Expand Down Expand Up @@ -338,6 +340,22 @@ suite('Interpreters Conda Service', () => {
assert.equal(condaExe, 'conda', 'Failed to identify conda.exe');
});

test('Must use \'python.condaPath\' setting if set', async () => {
condaPath = 'spam-spam-conda-spam-spam';
// We ensure that conda would otherwise be found.
processService.setup(p => p.exec(TypeMoq.It.isValue('conda'), TypeMoq.It.isValue(['--version'])))
.returns(() => Promise.resolve({ stdout: 'xyz' }))
.verifiable(TypeMoq.Times.never());

const condaExe = await condaService.getCondaFile();
assert.equal(condaExe, 'spam-spam-conda-spam-spam', 'Failed to identify conda.exe');

// We should not try to call other unwanted methods.
processService.verifyAll();
platformService.verify(p => p.isWindows, TypeMoq.Times.never());
registryInterpreterLocatorService.verify(r => r.getInterpreters(TypeMoq.It.isAny()), TypeMoq.Times.never());
});

test('Must use \'conda\' if is available in the current path', async () => {
processService.setup(p => p.exec(TypeMoq.It.isValue('conda'), TypeMoq.It.isValue(['--version']))).returns(() => Promise.resolve({ stdout: 'xyz' }));

Expand Down

0 comments on commit bad01ca

Please sign in to comment.