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.
Allow native REPL launch from command palette (#23912)
Resolves: #23727 Allow users to launch Native REPL via command palette. Will also be handling #23821 in this PR. -- setting proper workspace directory. Related: #23656 Covering scenarios: - Provide selection option if user is in multi-workspace scenario (already included in PR) - Automatically pick workspace as directory for context of REPL if user is in single-workspace scenario (already included in PR) - Handle case where user does not open any workspace and attempt to launch native REPL from plain/empty VS Code instance via command palette option (already included in PR)
- Loading branch information
1 parent
48e277a
commit e90b95d
Showing
11 changed files
with
191 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
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,70 @@ | ||
/* 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'; | ||
|
||
suite('REPL - Native REPL', () => { | ||
let interpreterService: TypeMoq.IMock<IInterpreterService>; | ||
|
||
let disposable: TypeMoq.IMock<Disposable>; | ||
let disposableArray: Disposable[] = []; | ||
|
||
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]; | ||
|
||
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(); | ||
} | ||
}); | ||
|
||
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); | ||
|
||
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)); | ||
|
||
await NativeRepl.create(interpreter as PythonEnvironment); | ||
|
||
expect(setReplDirectoryStub.calledOnce).to.be.true; | ||
expect(setReplControllerSpy.calledOnce).to.be.true; | ||
|
||
setReplDirectoryStub.restore(); | ||
setReplControllerSpy.restore(); | ||
}); | ||
}); |