Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Nov 14, 2024
1 parent 48c8686 commit 4a278e7
Show file tree
Hide file tree
Showing 2 changed files with 271 additions and 261 deletions.
116 changes: 59 additions & 57 deletions src/test/repl/nativeRepl.test.ts
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();
});
});
Loading

0 comments on commit 4a278e7

Please sign in to comment.