forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinterinfo.unit.test.ts
More file actions
97 lines (82 loc) · 4.01 KB
/
linterinfo.unit.test.ts
File metadata and controls
97 lines (82 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:chai-vague-errors no-unused-expression max-func-body-length no-any
import { expect } from 'chai';
import { anything, instance, mock, when } from 'ts-mockito';
import { WorkspaceService } from '../../client/common/application/workspace';
import { ConfigurationService } from '../../client/common/configuration/service';
import { PylintLinterInfo } from '../../client/linters/linterInfo';
suite('Linter Info - Pylint', () => {
test('Test disabled when Pylint is explicitly disabled', async () => {
const config = mock(ConfigurationService);
const workspaceService = mock(WorkspaceService);
const linterInfo = new PylintLinterInfo(instance(config), instance(workspaceService), []);
when(config.getSettings(anything())).thenReturn({ linting: { pylintEnabled: false } } as any);
expect(linterInfo.isEnabled()).to.be.false;
});
test('Test disabled when Jedi is enabled and Pylint is explicitly disabled', async () => {
const config = mock(ConfigurationService);
const workspaceService = mock(WorkspaceService);
const linterInfo = new PylintLinterInfo(instance(config), instance(workspaceService), []);
when(config.getSettings(anything())).thenReturn({
linting: { pylintEnabled: false },
jediEnabled: true
} as any);
expect(linterInfo.isEnabled()).to.be.false;
});
test('Test enabled when Jedi is enabled and Pylint is explicitly enabled', async () => {
const config = mock(ConfigurationService);
const workspaceService = mock(WorkspaceService);
const linterInfo = new PylintLinterInfo(instance(config), instance(workspaceService), []);
when(config.getSettings(anything())).thenReturn({ linting: { pylintEnabled: true }, jediEnabled: true } as any);
expect(linterInfo.isEnabled()).to.be.true;
});
test('Test disabled when using Language Server and Pylint is not configured', async () => {
const config = mock(ConfigurationService);
const workspaceService = mock(WorkspaceService);
const linterInfo = new PylintLinterInfo(instance(config), instance(workspaceService), []);
const inspection = {};
const pythonConfig = {
inspect: () => inspection
};
when(config.getSettings(anything())).thenReturn({
linting: { pylintEnabled: true },
jediEnabled: false
} as any);
when(workspaceService.getConfiguration('python', anything())).thenReturn(pythonConfig as any);
expect(linterInfo.isEnabled()).to.be.false;
});
const testsForisEnabled = [
{
testName: 'When workspaceFolder setting is provided',
inspection: { workspaceFolderValue: true }
},
{
testName: 'When workspace setting is provided',
inspection: { workspaceValue: true }
},
{
testName: 'When global setting is provided',
inspection: { globalValue: true }
}
];
suite('Test is enabled when using Language Server and Pylint is configured', () => {
testsForisEnabled.forEach(testParams => {
test(testParams.testName, async () => {
const config = mock(ConfigurationService);
const workspaceService = mock(WorkspaceService);
const linterInfo = new PylintLinterInfo(instance(config), instance(workspaceService), []);
const pythonConfig = {
inspect: () => testParams.inspection
};
when(config.getSettings(anything())).thenReturn({
linting: { pylintEnabled: true },
jediEnabled: false
} as any);
when(workspaceService.getConfiguration('python', anything())).thenReturn(pythonConfig as any);
expect(linterInfo.isEnabled()).to.be.true;
});
});
});
});