Skip to content

Commit

Permalink
Fix more tests and get browser to build
Browse files Browse the repository at this point in the history
  • Loading branch information
rchiodo committed Aug 23, 2024
1 parent 6b29258 commit 65fe549
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"env": {
"VSC_PYTHON_CI_TEST_GREP": "" // Modify this to run a subset of the single workspace tests
"VSC_PYTHON_CI_TEST_GREP": "Ensure pip is supported and conda is not" // Modify this to run a subset of the single workspace tests
},
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
Expand Down
106 changes: 106 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,7 @@
"chai-arrays": "^2.0.0",
"chai-as-promised": "^7.1.1",
"copy-webpack-plugin": "^9.1.0",
"cross-env": "^7.0.3",
"cross-spawn": "^6.0.5",
"del": "^6.0.0",
"download": "^8.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/test/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"python.linting.banditEnabled": false,
// Don't set this to `Pylance`, for CI we want to use the LS that ships with the extension.
"python.languageServer": "Jedi",
"python.pythonPath": "C:\\GIT\\s p\\vscode-python\\.venv\\Scripts\\python.exe"
"python.pythonPath": "C:\\GIT\\s p\\vscode-python\\.venv\\Scripts\\python.exe",
"python.defaultInterpreterPath": "python"
}
37 changes: 19 additions & 18 deletions src/test/common/moduleInstaller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import { MockModuleInstaller } from '../mocks/moduleInstaller';
import { MockProcessService } from '../mocks/proc';
import { UnitTestIocContainer } from '../testing/serviceRegistry';
import { closeActiveWindows, initializeTest } from '../initialize';
import { createTypeMoq } from '../mocks/helper';

chaiUse(chaiAsPromised.default);

Expand Down Expand Up @@ -149,8 +150,8 @@ suite('Module Installer', () => {
ioc.serviceManager.addSingleton<IProcessLogger>(IProcessLogger, ProcessLogger);
ioc.serviceManager.addSingleton<IInstaller>(IInstaller, ProductInstaller);

mockTerminalService = TypeMoq.Mock.ofType<ITerminalService>();
mockTerminalFactory = TypeMoq.Mock.ofType<ITerminalServiceFactory>();
mockTerminalService = createTypeMoq<ITerminalService>();
mockTerminalFactory = createTypeMoq<ITerminalServiceFactory>();
// If resource is provided, then ensure we do not invoke without the resource.
mockTerminalFactory
.setup((t) => t.getTerminalService(TypeMoq.It.isAny()))
Expand All @@ -160,11 +161,13 @@ suite('Module Installer', () => {
ITerminalServiceFactory,
mockTerminalFactory.object,
);
const activatedEnvironmentLaunch = mock<IActivatedEnvironmentLaunch>();
when(activatedEnvironmentLaunch.selectIfLaunchedViaActivatedEnv()).thenResolve(undefined);
const activatedEnvironmentLaunch = createTypeMoq<IActivatedEnvironmentLaunch>();
activatedEnvironmentLaunch
.setup((t) => t.selectIfLaunchedViaActivatedEnv())
.returns(() => Promise.resolve(undefined));
ioc.serviceManager.addSingletonInstance<IActivatedEnvironmentLaunch>(
IActivatedEnvironmentLaunch,
instance(activatedEnvironmentLaunch),
activatedEnvironmentLaunch.object,
);
ioc.serviceManager.addSingleton<IModuleInstaller>(IModuleInstaller, PipInstaller);
ioc.serviceManager.addSingleton<IModuleInstaller>(IModuleInstaller, CondaInstaller);
Expand All @@ -182,10 +185,10 @@ suite('Module Installer', () => {
ioc.serviceManager.addSingletonInstance<boolean>(IsWindows, false);

await ioc.registerMockInterpreterTypes();
condaService = TypeMoq.Mock.ofType<ICondaService>();
condaLocatorService = TypeMoq.Mock.ofType<IComponentAdapter>();
condaService = createTypeMoq<ICondaService>();
condaLocatorService = createTypeMoq<IComponentAdapter>();
ioc.serviceManager.rebindInstance<ICondaService>(ICondaService, condaService.object);
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();
interpreterService = createTypeMoq<IInterpreterService>();
ioc.serviceManager.rebindInstance<IInterpreterService>(IInterpreterService, interpreterService.object);

ioc.serviceManager.addSingleton<IActiveResourceService>(IActiveResourceService, ActiveResourceService);
Expand Down Expand Up @@ -267,10 +270,8 @@ suite('Module Installer', () => {
new MockModuleInstaller('mock', true),
);
ioc.serviceManager.addSingletonInstance<ITerminalHelper>(ITerminalHelper, instance(mock(TerminalHelper)));

const processService = (await ioc.serviceContainer
.get<IProcessServiceFactory>(IProcessServiceFactory)
.create()) as MockProcessService;
const factory = ioc.serviceManager.get<IProcessServiceFactory>(IProcessServiceFactory);
const processService = (await factory.create()) as MockProcessService;
processService.onExec((file, args, _options, callback) => {
if (args.length > 1 && args[0] === '-c' && args[1] === 'import pip') {
callback({ stdout: '' });
Expand Down Expand Up @@ -321,13 +322,13 @@ suite('Module Installer', () => {
await expect(pipInstaller.isSupported()).to.eventually.equal(true, 'Pip is not supported');
});
test('Ensure conda is supported', async () => {
const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
const serviceContainer = createTypeMoq<IServiceContainer>();

const configService = TypeMoq.Mock.ofType<IConfigurationService>();
const configService = createTypeMoq<IConfigurationService>();
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IConfigurationService)))
.returns(() => configService.object);
const settings = TypeMoq.Mock.ofType<IPythonSettings>();
const settings = createTypeMoq<IPythonSettings>();
const pythonPath = 'pythonABC';
settings.setup((s) => s.pythonPath).returns(() => pythonPath);
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);
Expand All @@ -347,13 +348,13 @@ suite('Module Installer', () => {
await expect(condaInstaller.isSupported()).to.eventually.equal(true, 'Conda is not supported');
});
test('Ensure conda is not supported even if conda is available', async () => {
const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
const serviceContainer = createTypeMoq<IServiceContainer>();

const configService = TypeMoq.Mock.ofType<IConfigurationService>();
const configService = createTypeMoq<IConfigurationService>();
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IConfigurationService)))
.returns(() => configService.object);
const settings = TypeMoq.Mock.ofType<IPythonSettings>();
const settings = createTypeMoq<IPythonSettings>();
const pythonPath = 'pythonABC';
settings.setup((s) => s.pythonPath).returns(() => pythonPath);
configService.setup((c) => c.getSettings(TypeMoq.It.isAny())).returns(() => settings.object);
Expand Down
3 changes: 2 additions & 1 deletion src/test/install/channelManager.channels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ServiceContainer } from '../../client/ioc/container';
import { ServiceManager } from '../../client/ioc/serviceManager';
import { IServiceContainer } from '../../client/ioc/types';
import { MockAutoSelectionService } from '../mocks/autoSelector';
import { createTypeMoq } from '../mocks/helper';

suite('Installation - installation channels', () => {
let serviceManager: ServiceManager;
Expand Down Expand Up @@ -98,7 +99,7 @@ suite('Installation - installation channels', () => {
});

function mockInstaller(supported: boolean, name: string, priority?: number): TypeMoq.IMock<IModuleInstaller> {
const installer = TypeMoq.Mock.ofType<IModuleInstaller>();
const installer = createTypeMoq<IModuleInstaller>();
installer
.setup((x) => x.isSupported(TypeMoq.It.isAny()))
.returns(
Expand Down
9 changes: 5 additions & 4 deletions src/test/install/channelManager.messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ServiceManager } from '../../client/ioc/serviceManager';
import { IServiceContainer } from '../../client/ioc/types';
import { EnvironmentType, PythonEnvironment } from '../../client/pythonEnvironments/info';
import { MockAutoSelectionService } from '../mocks/autoSelector';
import { createTypeMoq } from '../mocks/helper';

const info: PythonEnvironment = {
architecture: Architecture.Unknown,
Expand All @@ -45,16 +46,16 @@ suite('Installation - channel messages', () => {
const serviceManager = new ServiceManager(cont);
serviceContainer = new ServiceContainer(cont);

platform = TypeMoq.Mock.ofType<IPlatformService>();
platform = createTypeMoq<IPlatformService>();
serviceManager.addSingletonInstance<IPlatformService>(IPlatformService, platform.object);

appShell = TypeMoq.Mock.ofType<IApplicationShell>();
appShell = createTypeMoq<IApplicationShell>();
serviceManager.addSingletonInstance<IApplicationShell>(IApplicationShell, appShell.object);

interpreters = TypeMoq.Mock.ofType<IInterpreterService>();
interpreters = createTypeMoq<IInterpreterService>();
serviceManager.addSingletonInstance<IInterpreterService>(IInterpreterService, interpreters.object);

const moduleInstaller = TypeMoq.Mock.ofType<IModuleInstaller>();
const moduleInstaller = createTypeMoq<IModuleInstaller>();
serviceManager.addSingletonInstance<IModuleInstaller>(IModuleInstaller, moduleInstaller.object);
serviceManager.addSingleton<IInterpreterAutoSelectionService>(
IInterpreterAutoSelectionService,
Expand Down
13 changes: 6 additions & 7 deletions src/test/serviceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { MockMemento } from './mocks/mementos';
import { MockProcessService } from './mocks/proc';
import { MockProcess } from './mocks/process';
import { registerForIOC } from './pythonEnvironments/legacyIOC';
import { createTypeMoq } from './mocks/helper';

export class IocContainer {
// This may be set (before any registration happens) to indicate
Expand Down Expand Up @@ -125,12 +126,10 @@ export class IocContainer {

public registerProcessTypes(): void {
processRegisterTypes(this.serviceManager);
const mockEnvironmentActivationService = mock(EnvironmentActivationService);
when(mockEnvironmentActivationService.getActivatedEnvironmentVariables(anything())).thenResolve();
this.serviceManager.addSingletonInstance<IEnvironmentActivationService>(
IEnvironmentActivationService,
instance(mockEnvironmentActivationService),
);
const mockEnvironmentActivationService = createTypeMoq<IEnvironmentActivationService>();
mockEnvironmentActivationService
.setup((f) => f.getActivatedEnvironmentVariables(anything()))
.returns(() => Promise.resolve(undefined));
}

public registerVariableTypes(): void {
Expand All @@ -151,7 +150,7 @@ export class IocContainer {
}

public registerMockProcessTypes(): void {
const processServiceFactory = TypeMoq.Mock.ofType<IProcessServiceFactory>();
const processServiceFactory = createTypeMoq<IProcessServiceFactory>();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const processService = new MockProcessService(new ProcessService(process.env as any));
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"include": [
"./src/client/browser",
"./types"
"./types",
"./typings/*.d.ts",
]
}

0 comments on commit 65fe549

Please sign in to comment.