forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.manager.unit.test.ts
More file actions
101 lines (78 loc) · 3.86 KB
/
Copy pathlint.manager.unit.test.ts
File metadata and controls
101 lines (78 loc) · 3.86 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
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import { Uri } from 'vscode';
import { IWorkspaceService } from '../../client/common/application/types';
import { IConfigurationService, IPythonSettings } from '../../client/common/types';
import { IServiceContainer } from '../../client/ioc/types';
import { LinterManager } from '../../client/linters/linterManager';
// setup class instance
class TestLinterManager extends LinterManager {
public enableUnconfiguredLintersCallCount: number = 0;
protected async enableUnconfiguredLinters(_resource?: Uri): Promise<void> {
this.enableUnconfiguredLintersCallCount += 1;
}
}
function getServiceContainerMockForLinterManagerTests(): TypeMoq.IMock<IServiceContainer> {
// setup test mocks
const serviceContainerMock = TypeMoq.Mock.ofType<IServiceContainer>();
const configMock = TypeMoq.Mock.ofType<IConfigurationService>();
const pythonSettingsMock = TypeMoq.Mock.ofType<IPythonSettings>();
configMock.setup(cm => cm.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettingsMock.object);
serviceContainerMock.setup(c => c.get(IConfigurationService)).returns(() => configMock.object);
return serviceContainerMock;
}
// tslint:disable-next-line:max-func-body-length
suite('Lint Manager Unit Tests', () => {
const workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
test('Linter manager isLintingEnabled checks availability when silent = false.', async () => {
// set expectations
const expectedCallCount = 1;
const silentFlag = false;
// get setup
const serviceContainerMock = getServiceContainerMockForLinterManagerTests();
// make the call
const lm = new TestLinterManager(serviceContainerMock.object, workspaceService.object);
await lm.isLintingEnabled(silentFlag);
// test expectations
expect(lm.enableUnconfiguredLintersCallCount).to.equal(expectedCallCount);
});
test('Linter manager isLintingEnabled does not check availability when silent = true.', async () => {
// set expectations
const expectedCallCount = 0;
const silentFlag = true;
// get setup
const serviceContainerMock = getServiceContainerMockForLinterManagerTests();
// make the call
const lm: TestLinterManager = new TestLinterManager(serviceContainerMock.object, workspaceService.object);
await lm.isLintingEnabled(silentFlag);
// test expectations
expect(lm.enableUnconfiguredLintersCallCount).to.equal(expectedCallCount);
});
test('Linter manager getActiveLinters checks availability when silent = false.', async () => {
// set expectations
const expectedCallCount = 1;
const silentFlag = false;
// get setup
const serviceContainerMock = getServiceContainerMockForLinterManagerTests();
// make the call
const lm: TestLinterManager = new TestLinterManager(serviceContainerMock.object, workspaceService.object);
await lm.getActiveLinters(silentFlag);
// test expectations
expect(lm.enableUnconfiguredLintersCallCount).to.equal(expectedCallCount);
});
test('Linter manager getActiveLinters checks availability when silent = true.', async () => {
// set expectations
const expectedCallCount = 0;
const silentFlag = true;
// get setup
const serviceContainerMock = getServiceContainerMockForLinterManagerTests();
// make the call
const lm: TestLinterManager = new TestLinterManager(serviceContainerMock.object, workspaceService.object);
await lm.getActiveLinters(silentFlag);
// test expectations
expect(lm.enableUnconfiguredLintersCallCount).to.equal(expectedCallCount);
});
});