Skip to content

Commit 592717d

Browse files
committed
fix tests for real
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent a23a0cb commit 592717d

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

src/test/common/configSettings/configSettings.unit.test.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ suite('Python Settings', async () => {
4141
let config: TypeMoq.IMock<WorkspaceConfiguration>;
4242
let expected: CustomPythonSettings;
4343
let settings: CustomPythonSettings;
44+
let extensions: MockExtensions;
4445
setup(() => {
4546
sinon.stub(EnvFileTelemetry, 'sendSettingTelemetry').returns();
4647
config = TypeMoq.Mock.ofType<WorkspaceConfiguration>(undefined, TypeMoq.MockBehavior.Loose);
4748

4849
const workspaceService = new WorkspaceService();
4950
const workspaceMemento = new MockMemento();
5051
const globalMemento = new MockMemento();
51-
const extensions = new MockExtensions();
52+
extensions = new MockExtensions();
5253
const persistentStateFactory = new PersistentStateFactory(globalMemento, workspaceMemento);
5354
expected = new CustomPythonSettings(
5455
undefined,
@@ -57,7 +58,7 @@ suite('Python Settings', async () => {
5758
new InterpreterPathService(persistentStateFactory, workspaceService, [], {
5859
remoteName: undefined,
5960
} as IApplicationEnvironment),
60-
undefined,
61+
{ defaultLSType: LanguageServerType.Jedi },
6162
extensions,
6263
);
6364
settings = new CustomPythonSettings(
@@ -67,7 +68,7 @@ suite('Python Settings', async () => {
6768
new InterpreterPathService(persistentStateFactory, workspaceService, [], {
6869
remoteName: undefined,
6970
} as IApplicationEnvironment),
70-
undefined,
71+
{ defaultLSType: LanguageServerType.Jedi },
7172
extensions,
7273
);
7374
expected.defaultInterpreterPath = 'python';
@@ -230,7 +231,7 @@ suite('Python Settings', async () => {
230231
const values = [
231232
{ ls: LanguageServerType.Jedi, expected: LanguageServerType.Jedi, default: false },
232233
{ ls: LanguageServerType.JediLSP, expected: LanguageServerType.Jedi, default: false },
233-
{ ls: LanguageServerType.Microsoft, expected: LanguageServerType.None, default: true },
234+
{ ls: LanguageServerType.Microsoft, expected: LanguageServerType.Jedi, default: true },
234235
{ ls: LanguageServerType.Node, expected: LanguageServerType.Node, default: false },
235236
{ ls: LanguageServerType.None, expected: LanguageServerType.None, default: false },
236237
];
@@ -239,7 +240,48 @@ suite('Python Settings', async () => {
239240
testLanguageServer(v.ls, v.expected, v.default);
240241
});
241242

242-
testLanguageServer('invalid' as LanguageServerType, LanguageServerType.None, true);
243+
testLanguageServer('invalid' as LanguageServerType, LanguageServerType.Jedi, true);
244+
});
245+
246+
function testPyreflySettings(pyreflyInstalled: boolean, pyreflyDisabled: boolean, languageServerDisabled: boolean) {
247+
test(`pyrefly ${pyreflyInstalled ? 'installed' : 'not installed'} and ${
248+
pyreflyDisabled ? 'disabled' : 'enabled'
249+
}`, () => {
250+
if (pyreflyInstalled) {
251+
extensions.extensionIdsToFind = ['meta.pyrefly'];
252+
} else {
253+
extensions.extensionIdsToFind = [];
254+
}
255+
config.setup((c) => c.get<boolean>('pyrefly.disableLanguageServices')).returns(() => pyreflyDisabled);
256+
257+
config
258+
.setup((c) => c.get<string>('languageServer'))
259+
.returns(() => undefined)
260+
.verifiable(TypeMoq.Times.once());
261+
262+
settings.update(config.object);
263+
264+
if (languageServerDisabled) {
265+
expect(settings.languageServer).to.equal(LanguageServerType.None);
266+
} else {
267+
expect(settings.languageServer).not.to.equal(LanguageServerType.None);
268+
}
269+
expect(settings.languageServerIsDefault).to.equal(true);
270+
config.verifyAll();
271+
});
272+
}
273+
274+
suite('pyrefly languageServer settings', async () => {
275+
const values = [
276+
{ pyreflyInstalled: true, pyreflyDisabled: false, languageServerDisabled: true },
277+
{ pyreflyInstalled: true, pyreflyDisabled: true, languageServerDisabled: false },
278+
{ pyreflyInstalled: false, pyreflyDisabled: true, languageServerDisabled: false },
279+
{ pyreflyInstalled: false, pyreflyDisabled: false, languageServerDisabled: false },
280+
];
281+
282+
values.forEach((v) => {
283+
testPyreflySettings(v.pyreflyInstalled, v.pyreflyDisabled, v.languageServerDisabled);
284+
});
243285
});
244286

245287
function testExperiments(enabled: boolean) {

src/test/mocks/extension.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { injectable } from 'inversify';
2+
import { Extension, ExtensionKind, Uri } from 'vscode';
3+
4+
@injectable()
5+
export class MockExtension<T> implements Extension<T> {
6+
id!: string;
7+
extensionUri!: Uri;
8+
extensionPath!: string;
9+
isActive!: boolean;
10+
packageJSON: any;
11+
extensionKind!: ExtensionKind;
12+
exports!: T;
13+
activate(): Thenable<T> {
14+
throw new Error('Method not implemented.');
15+
}
16+
}

src/test/mocks/extensions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { injectable } from 'inversify';
22
import { IExtensions } from '../../client/common/types';
33
import { Extension, Event } from 'vscode';
4+
import { MockExtension } from './extension';
45

56
@injectable()
67
export class MockExtensions implements IExtensions {
8+
extensionIdsToFind: unknown[] = [];
79
all: readonly Extension<unknown>[] = [];
810
onDidChange: Event<void> = () => {
911
throw new Error('Method not implemented');
1012
};
1113
getExtension(extensionId: string): Extension<unknown> | undefined;
1214
getExtension<T>(extensionId: string): Extension<T> | undefined;
13-
getExtension(_extensionId: unknown): import('vscode').Extension<unknown> | undefined {
14-
throw new Error('Method not implemented.');
15+
getExtension(extensionId: unknown): import('vscode').Extension<unknown> | undefined {
16+
if (this.extensionIdsToFind.includes(extensionId)) {
17+
return new MockExtension();
18+
}
1519
}
1620
determineExtensionFromCallStack(): Promise<{ extensionId: string; displayName: string }> {
1721
throw new Error('Method not implemented.');

0 commit comments

Comments
 (0)