Skip to content

Commit

Permalink
Fix startup telemetry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Jan 6, 2022
1 parent d905c66 commit e7d3de9
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/test/startupTelemetry.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import { Uri, WorkspaceConfiguration } from 'vscode';
import { Uri } from 'vscode';
import { IWorkspaceService } from '../client/common/application/types';
import { DeprecatePythonPath } from '../client/common/experiments/groups';
import { IExperimentService, IInterpreterPathService } from '../client/common/types';
Expand All @@ -28,26 +28,12 @@ suite('Startup Telemetry - hasUserDefinedPythonPath()', async () => {
serviceContainer.setup((s) => s.get(IInterpreterPathService)).returns(() => interpreterPathService.object);
});

function setupConfigProvider(): TypeMoq.IMock<WorkspaceConfiguration> {
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
workspaceService
.setup((w) => w.getConfiguration(TypeMoq.It.isValue('python'), TypeMoq.It.isValue(resource)))
.returns(() => workspaceConfig.object);
return workspaceConfig;
}

[undefined, 'python'].forEach((globalValue) => {
[undefined, 'python'].forEach((workspaceValue) => {
[undefined, 'python'].forEach((workspaceFolderValue) => {
test(`Return false if using settings equals {globalValue: ${globalValue}, workspaceValue: ${workspaceValue}, workspaceFolderValue: ${workspaceFolderValue}}`, () => {
experimentsManager
.setup((e) => e.inExperimentSync(DeprecatePythonPath.experiment))
.returns(() => false);
const workspaceConfig = setupConfigProvider();

workspaceConfig
.setup((w) => w.inspect('pythonPath'))

interpreterPathService
.setup((i) => i.inspect(resource))
.returns(() => ({ globalValue, workspaceValue, workspaceFolderValue } as any));
const result = hasUserDefinedPythonPath(resource, serviceContainer.object);
expect(result).to.equal(false, 'Should be false');
Expand All @@ -58,19 +44,16 @@ suite('Startup Telemetry - hasUserDefinedPythonPath()', async () => {

test('Return true if using setting value equals something else', () => {
experimentsManager.setup((e) => e.inExperimentSync(DeprecatePythonPath.experiment)).returns(() => false);
const workspaceConfig = setupConfigProvider();

workspaceConfig.setup((w) => w.inspect('pythonPath')).returns(() => ({ globalValue: 'something else' } as any));
interpreterPathService
.setup((i) => i.inspect(resource))
.returns(() => ({ globalValue: 'something else' } as any));
const result = hasUserDefinedPythonPath(resource, serviceContainer.object);
expect(result).to.equal(true, 'Should be true');
});

test('If in Deprecate PythonPath experiment, use the new API to inspect settings', () => {
experimentsManager.setup((e) => e.inExperimentSync(DeprecatePythonPath.experiment)).returns(() => true);
interpreterPathService
.setup((i) => i.inspect(resource))
.returns(() => ({}))
.verifiable(TypeMoq.Times.once());
interpreterPathService.setup((i) => i.inspect(resource)).returns(() => ({}));
hasUserDefinedPythonPath(resource, serviceContainer.object);
interpreterPathService.verifyAll();
});
Expand Down

0 comments on commit e7d3de9

Please sign in to comment.