Skip to content

Add Testing for PytestExecutionAdapter #21019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// /* eslint-disable @typescript-eslint/no-explicit-any */
// // Copyright (c) Microsoft Corporation. All rights reserved.
// // Licensed under the MIT License.
// import * as assert from 'assert';
// import { Uri } from 'vscode';
// import * as typeMoq from 'typemoq';
// import { IConfigurationService } from '../../../../client/common/types';
// import { DataReceivedEvent, ITestServer } from '../../../../client/testing/testController/common/types';
// import { IPythonExecutionFactory, IPythonExecutionService } from '../../../../client/common/process/types';
// import { createDeferred, Deferred } from '../../../../client/common/utils/async';
// import { PytestTestExecutionAdapter } from '../../../../client/testing/testController/pytest/pytestExecutionAdapter';

// suite('pytest test execution adapter', () => {
// let testServer: typeMoq.IMock<ITestServer>;
// let configService: IConfigurationService;
// let execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
// let adapter: PytestTestExecutionAdapter;
// let execService: typeMoq.IMock<IPythonExecutionService>;
// let deferred: Deferred<void>;
// setup(() => {
// testServer = typeMoq.Mock.ofType<ITestServer>();
// testServer.setup((t) => t.getPort()).returns(() => 12345);
// testServer
// .setup((t) => t.onDataReceived(typeMoq.It.isAny(), typeMoq.It.isAny()))
// .returns(() => ({
// dispose: () => {
// /* no-body */
// },
// }));
// configService = ({
// getSettings: () => ({
// testing: { pytestArgs: ['.'] },
// }),
// isTestExecution: () => false,
// } as unknown) as IConfigurationService;
// execFactory = typeMoq.Mock.ofType<IPythonExecutionFactory>();
// execService = typeMoq.Mock.ofType<IPythonExecutionService>();
// execFactory
// .setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny()))
// .returns(() => Promise.resolve(execService.object));
// deferred = createDeferred();
// execService
// .setup((x) => x.exec(typeMoq.It.isAny(), typeMoq.It.isAny()))
// .returns(() => {
// deferred.resolve();
// return Promise.resolve({ stdout: '{}' });
// });
// execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
// execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined);
// });
// test('onDataReceivedHandler should parse only if known UUID', async () => {
// const uri = Uri.file('/my/test/path/');
// const uuid = 'uuid123';
// const data = { status: 'success' };
// testServer.setup((t) => t.createUUID(typeMoq.It.isAny())).returns(() => uuid);
// const eventData: DataReceivedEvent = {
// uuid,
// data: JSON.stringify(data),
// };

// adapter = new PytestTestExecutionAdapter(testServer.object, configService);
// const promise = adapter.runTests(uri, [], false);
// await deferred.promise;
// adapter.onDataReceivedHandler(eventData);
// const result = await promise;
// assert.deepStrictEqual(result, data);
// });
// test('onDataReceivedHandler should not parse if it is unknown UUID', async () => {
// const uri = Uri.file('/my/test/path/');
// const uuid = 'uuid456';
// let data = { status: 'error' };
// testServer.setup((t) => t.createUUID(typeMoq.It.isAny())).returns(() => uuid);
// const wrongUriEventData: DataReceivedEvent = {
// uuid: 'incorrect-uuid456',
// data: JSON.stringify(data),
// };
// adapter = new PytestTestExecutionAdapter(testServer.object, configService);
// const promise = adapter.runTests(uri, [], false);
// adapter.onDataReceivedHandler(wrongUriEventData);

// data = { status: 'success' };
// const correctUriEventData: DataReceivedEvent = {
// uuid,
// data: JSON.stringify(data),
// };
// adapter.onDataReceivedHandler(correctUriEventData);
// const result = await promise;
// assert.deepStrictEqual(result, data);
// });
// });