forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Testing for PytestExecutionAdapter (#21019)
- Loading branch information
1 parent
f4f883c
commit c64bb0e
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// }); | ||
// }); |