Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Oct 14, 2024
1 parent 8b3b976 commit 9932f43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
54 changes: 27 additions & 27 deletions src/client/pythonEnvironments/nativeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,32 @@ function toPythonEnvInfo(nativeEnv: NativeEnvInfo): PythonEnvInfo | undefined {
};
}

function hasChanged(old: PythonEnvInfo, newEnv: PythonEnvInfo): boolean {
if (old.executable.filename !== newEnv.executable.filename) {
return true;
}
if (old.version.major !== newEnv.version.major) {
return true;
}
if (old.version.minor !== newEnv.version.minor) {
return true;
}
if (old.version.micro !== newEnv.version.micro) {
return true;
}
if (old.location !== newEnv.location) {
return true;
}
if (old.kind !== newEnv.kind) {
return true;
}
if (old.arch !== newEnv.arch) {
return true;
}

return false;
}

class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
private _onProgress: EventEmitter<ProgressNotificationEvent>;

Expand Down Expand Up @@ -354,37 +380,11 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable {
return this._envs;
}

private hasChanged(old: PythonEnvInfo, newEnv: PythonEnvInfo): boolean {
if (old.executable.filename !== newEnv.executable.filename) {
return true;
}
if (old.version.major !== newEnv.version.major) {
return true;
}
if (old.version.minor !== newEnv.version.minor) {
return true;
}
if (old.version.micro !== newEnv.version.micro) {
return true;
}
if (old.location !== newEnv.location) {
return true;
}
if (old.kind !== newEnv.kind) {
return true;
}
if (old.arch !== newEnv.arch) {
return true;
}

return false;
}

private addEnv(native: NativeEnvInfo, searchLocation?: Uri): PythonEnvInfo | undefined {
const info = toPythonEnvInfo(native);
if (info) {
const old = this._envs.find((item) => item.executable.filename === info.executable.filename);
if (old && this.hasChanged(old, info)) {
if (old && hasChanged(old, info)) {
this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename);
this._envs.push(info);
this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation });
Expand Down
2 changes: 1 addition & 1 deletion src/test/pythonEnvironments/nativeAPI.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ suite('Native Python API', () => {
mtime: -1,
},
kind: PythonEnvKind.Conda,
location: '/home/user/.conda/envs/conda_python/python',
location: '/home/user/.conda/envs/conda_python',
source: [],
name: 'conda_python',
type: PythonEnvType.Conda,
Expand Down

0 comments on commit 9932f43

Please sign in to comment.