From 86da249222505fe3fe273f35554a9300938cc4cc Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 22 Jul 2024 18:24:56 -0700 Subject: [PATCH] Tests --- src/client/pythonEnvironments/nativeAPI.ts | 5 ++--- .../pythonEnvironments/nativeAPI.unit.test.ts | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index c12d8c0b8994b..1910b7e1894ad 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -164,7 +164,7 @@ function getName(nativeEnv: NativeEnvInfo, kind: PythonEnvKind): string { return ''; } -function toPythonEnvInfo(nativeEnv: NativeEnvInfo, searchLocation?: Uri): PythonEnvInfo | undefined { +function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined { if (!validEnv(nativeEnv)) { return undefined; } @@ -202,7 +202,6 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo, searchLocation?: Uri): Python detailedDisplayName: displayName, display: displayName, type: getEnvType(kind), - searchLocation, }; } @@ -342,7 +341,7 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { } private addEnv(native: NativeEnvInfo, searchLocation?: Uri): PythonEnvInfo | undefined { - const info = toPythonEnvInfo(native, searchLocation); + const info = toPythonEnvInfo(native); if (info) { const old = this._envs.find((item) => item.executable.filename === info.executable.filename); if (old) { diff --git a/src/test/pythonEnvironments/nativeAPI.unit.test.ts b/src/test/pythonEnvironments/nativeAPI.unit.test.ts index 2f122d850280f..73d8c58ff4a85 100644 --- a/src/test/pythonEnvironments/nativeAPI.unit.test.ts +++ b/src/test/pythonEnvironments/nativeAPI.unit.test.ts @@ -19,12 +19,17 @@ import { isWindows } from '../../client/common/platform/platformService'; import { NativePythonEnvironmentKind } from '../../client/pythonEnvironments/base/locators/common/nativePythonUtils'; import * as condaApi from '../../client/pythonEnvironments/common/environmentManagers/conda'; import * as pyenvApi from '../../client/pythonEnvironments/common/environmentManagers/pyenv'; +import * as pw from '../../client/pythonEnvironments/base/locators/common/pythonWatcher'; +import * as ws from '../../client/common/vscodeApis/workspaceApis'; suite('Native Python API', () => { let api: IDiscoveryAPI; let mockFinder: typemoq.IMock; let setCondaBinaryStub: sinon.SinonStub; let setPyEnvBinaryStub: sinon.SinonStub; + let createPythonWatcherStub: sinon.SinonStub; + let mockWatcher: typemoq.IMock; + let getWorkspaceFoldersStub: sinon.SinonStub; const basicEnv: NativeEnvInfo = { displayName: 'Basic Python', @@ -131,11 +136,22 @@ suite('Native Python API', () => { }; setup(() => { - mockFinder = typemoq.Mock.ofType(); - api = nativeAPI.createNativeEnvironmentsApi(mockFinder.object); - setCondaBinaryStub = sinon.stub(condaApi, 'setCondaBinary'); setPyEnvBinaryStub = sinon.stub(pyenvApi, 'setPyEnvBinary'); + getWorkspaceFoldersStub = sinon.stub(ws, 'getWorkspaceFolders'); + getWorkspaceFoldersStub.returns([]); + + createPythonWatcherStub = sinon.stub(pw, 'createPythonWatcher'); + mockWatcher = typemoq.Mock.ofType(); + createPythonWatcherStub.returns(mockWatcher.object); + + mockWatcher.setup((w) => w.watchWorkspace(typemoq.It.isAny())).returns(() => undefined); + mockWatcher.setup((w) => w.watchPath(typemoq.It.isAny(), typemoq.It.isAny())).returns(() => undefined); + mockWatcher.setup((w) => w.unwatchWorkspace(typemoq.It.isAny())).returns(() => undefined); + mockWatcher.setup((w) => w.unwatchPath(typemoq.It.isAny())).returns(() => undefined); + + mockFinder = typemoq.Mock.ofType(); + api = nativeAPI.createNativeEnvironmentsApi(mockFinder.object); }); teardown(() => {