Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Jul 23, 2024
1 parent d49374d commit 86da249
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/client/pythonEnvironments/nativeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -202,7 +202,6 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo, searchLocation?: Uri): Python
detailedDisplayName: displayName,
display: displayName,
type: getEnvType(kind),
searchLocation,
};
}

Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 19 additions & 3 deletions src/test/pythonEnvironments/nativeAPI.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NativePythonFinder>;
let setCondaBinaryStub: sinon.SinonStub;
let setPyEnvBinaryStub: sinon.SinonStub;
let createPythonWatcherStub: sinon.SinonStub;
let mockWatcher: typemoq.IMock<pw.PythonWatcher>;
let getWorkspaceFoldersStub: sinon.SinonStub;

const basicEnv: NativeEnvInfo = {
displayName: 'Basic Python',
Expand Down Expand Up @@ -131,11 +136,22 @@ suite('Native Python API', () => {
};

setup(() => {
mockFinder = typemoq.Mock.ofType<NativePythonFinder>();
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<pw.PythonWatcher>();
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<NativePythonFinder>();
api = nativeAPI.createNativeEnvironmentsApi(mockFinder.object);
});

teardown(() => {
Expand Down

0 comments on commit 86da249

Please sign in to comment.