From 9932f43e1acbdde0a418b08acea883580d7933d6 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 14 Oct 2024 08:16:51 -0700 Subject: [PATCH] Fix tests --- src/client/pythonEnvironments/nativeAPI.ts | 54 +++++++++---------- .../pythonEnvironments/nativeAPI.unit.test.ts | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index 98f56d9e10fe..31ad80608283 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -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; @@ -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 }); diff --git a/src/test/pythonEnvironments/nativeAPI.unit.test.ts b/src/test/pythonEnvironments/nativeAPI.unit.test.ts index 088a44a0c1a3..f7f956c7a20e 100644 --- a/src/test/pythonEnvironments/nativeAPI.unit.test.ts +++ b/src/test/pythonEnvironments/nativeAPI.unit.test.ts @@ -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,