Skip to content

Commit a7e9586

Browse files
authored
Add tests (#5215)
* Add tests * Add tests * Add tests
1 parent 9280372 commit a7e9586

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { expect } from 'chai';
7+
import * as typemoq from 'typemoq';
8+
import { ExecuteVSCCommand } from '../../../../client/application/diagnostics/commands/execVSCCommand';
9+
import { DiagnosticsCommandFactory } from '../../../../client/application/diagnostics/commands/factory';
10+
import { IDiagnosticsCommandFactory } from '../../../../client/application/diagnostics/commands/types';
11+
import { IDiagnostic } from '../../../../client/application/diagnostics/types';
12+
import { ICommandManager } from '../../../../client/common/application/types';
13+
import { IServiceContainer } from '../../../../client/ioc/types';
14+
15+
suite('Application Diagnostics - Exec VSC Commands', () => {
16+
let commandFactory: IDiagnosticsCommandFactory;
17+
let commandManager: typemoq.IMock<ICommandManager>;
18+
setup(() => {
19+
const serviceContainer = typemoq.Mock.ofType<IServiceContainer>();
20+
commandManager = typemoq.Mock.ofType<ICommandManager>();
21+
serviceContainer
22+
.setup(svc => svc.get<ICommandManager>(typemoq.It.isValue(ICommandManager), typemoq.It.isAny()))
23+
.returns(() => commandManager.object);
24+
commandFactory = new DiagnosticsCommandFactory(serviceContainer.object);
25+
});
26+
27+
test('Test creation of VSC Command', async () => {
28+
const diagnostic = typemoq.Mock.ofType<IDiagnostic>();
29+
30+
const command = commandFactory.createCommand(diagnostic.object, { type: 'executeVSCCommand', options: 'editor.action.formatDocument' });
31+
expect(command).to.be.instanceOf(ExecuteVSCCommand);
32+
});
33+
34+
test('Test execution of VSC Command', async () => {
35+
const diagnostic = typemoq.Mock.ofType<IDiagnostic>();
36+
commandManager
37+
.setup(cmd => cmd.executeCommand('editor.action.formatDocument'))
38+
.returns(() => Promise.resolve(undefined))
39+
.verifiable(typemoq.Times.once());
40+
41+
const command = commandFactory.createCommand(diagnostic.object, { type: 'executeVSCCommand', options: 'editor.action.formatDocument' });
42+
await command.invoke();
43+
44+
expect(command).to.be.instanceOf(ExecuteVSCCommand);
45+
commandManager.verifyAll();
46+
});
47+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)