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.
- Loading branch information
1 parent
48c8686
commit 4a278e7
Showing
2 changed files
with
271 additions
and
261 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,70 +1,72 @@ | ||
// /* eslint-disable no-unused-expressions */ | ||
// /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// import * as TypeMoq from 'typemoq'; | ||
// import * as sinon from 'sinon'; | ||
// import { Disposable } from 'vscode'; | ||
// import { expect } from 'chai'; | ||
/* eslint-disable no-unused-expressions */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import * as TypeMoq from 'typemoq'; | ||
import * as sinon from 'sinon'; | ||
import { Disposable } from 'vscode'; | ||
import { expect } from 'chai'; | ||
|
||
// import { IInterpreterService } from '../../client/interpreter/contracts'; | ||
// import { PythonEnvironment } from '../../client/pythonEnvironments/info'; | ||
// import { getNativeRepl, NativeRepl } from '../../client/repl/nativeRepl'; | ||
import { IInterpreterService } from '../../client/interpreter/contracts'; | ||
import { PythonEnvironment } from '../../client/pythonEnvironments/info'; | ||
import { getNativeRepl, NativeRepl } from '../../client/repl/nativeRepl'; | ||
import { IExtensionContext } from '../../client/common/types'; | ||
|
||
// suite('REPL - Native REPL', () => { | ||
// let interpreterService: TypeMoq.IMock<IInterpreterService>; | ||
suite('REPL - Native REPL', () => { | ||
let interpreterService: TypeMoq.IMock<IInterpreterService>; | ||
let extensionContext: TypeMoq.IMock<IExtensionContext>; | ||
let disposable: TypeMoq.IMock<Disposable>; | ||
let disposableArray: Disposable[] = []; | ||
|
||
// let disposable: TypeMoq.IMock<Disposable>; | ||
// let disposableArray: Disposable[] = []; | ||
let setReplDirectoryStub: sinon.SinonStub; | ||
let setReplControllerSpy: sinon.SinonSpy; | ||
|
||
// let setReplDirectoryStub: sinon.SinonStub; | ||
// let setReplControllerSpy: sinon.SinonSpy; | ||
setup(() => { | ||
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>(); | ||
interpreterService | ||
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
.returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
disposable = TypeMoq.Mock.ofType<Disposable>(); | ||
disposableArray = [disposable.object]; | ||
|
||
// setup(() => { | ||
// interpreterService = TypeMoq.Mock.ofType<IInterpreterService>(); | ||
// interpreterService | ||
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
// disposable = TypeMoq.Mock.ofType<Disposable>(); | ||
// disposableArray = [disposable.object]; | ||
setReplDirectoryStub = sinon.stub(NativeRepl.prototype as any, 'setReplDirectory').resolves(); // Stubbing private method | ||
// Use a spy instead of a stub for setReplController | ||
setReplControllerSpy = sinon.spy(NativeRepl.prototype, 'setReplController'); | ||
extensionContext = TypeMoq.Mock.ofType<IExtensionContext>(); | ||
}); | ||
|
||
// setReplDirectoryStub = sinon.stub(NativeRepl.prototype as any, 'setReplDirectory').resolves(); // Stubbing private method | ||
// // Use a spy instead of a stub for setReplController | ||
// setReplControllerSpy = sinon.spy(NativeRepl.prototype, 'setReplController'); | ||
// }); | ||
teardown(() => { | ||
disposableArray.forEach((d) => { | ||
if (d) { | ||
d.dispose(); | ||
} | ||
}); | ||
|
||
// teardown(() => { | ||
// disposableArray.forEach((d) => { | ||
// if (d) { | ||
// d.dispose(); | ||
// } | ||
// }); | ||
disposableArray = []; | ||
sinon.restore(); | ||
}); | ||
|
||
// disposableArray = []; | ||
// sinon.restore(); | ||
// }); | ||
test('getNativeRepl should call create constructor', async () => { | ||
const createMethodStub = sinon.stub(NativeRepl, 'create'); | ||
interpreterService | ||
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
.returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
const interpreter = await interpreterService.object.getActiveInterpreter(); | ||
await getNativeRepl(interpreter as PythonEnvironment, disposableArray, extensionContext.object); | ||
|
||
// test('getNativeRepl should call create constructor', async () => { | ||
// const createMethodStub = sinon.stub(NativeRepl, 'create'); | ||
// interpreterService | ||
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
// const interpreter = await interpreterService.object.getActiveInterpreter(); | ||
// await getNativeRepl(interpreter as PythonEnvironment, disposableArray); | ||
expect(createMethodStub.calledOnce).to.be.true; | ||
}); | ||
|
||
// expect(createMethodStub.calledOnce).to.be.true; | ||
// }); | ||
test('create should call setReplDirectory, setReplController', async () => { | ||
const interpreter = await interpreterService.object.getActiveInterpreter(); | ||
interpreterService | ||
.setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
.returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
|
||
// test('create should call setReplDirectory, setReplController', async () => { | ||
// const interpreter = await interpreterService.object.getActiveInterpreter(); | ||
// interpreterService | ||
// .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) | ||
// .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); | ||
await NativeRepl.create(interpreter as PythonEnvironment, extensionContext.object); | ||
|
||
// await NativeRepl.create(interpreter as PythonEnvironment); | ||
expect(setReplDirectoryStub.calledOnce).to.be.true; | ||
expect(setReplControllerSpy.calledOnce).to.be.true; | ||
|
||
// expect(setReplDirectoryStub.calledOnce).to.be.true; | ||
// expect(setReplControllerSpy.calledOnce).to.be.true; | ||
|
||
// setReplDirectoryStub.restore(); | ||
// setReplControllerSpy.restore(); | ||
// }); | ||
// }); | ||
setReplDirectoryStub.restore(); | ||
setReplControllerSpy.restore(); | ||
}); | ||
}); |
Oops, something went wrong.