Skip to content

Commit 403a86e

Browse files
author
Kartik Raj
committed
Add/fix tests
1 parent 42e2474 commit 403a86e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
150150
public async clearAndReloadFromStorage(): Promise<void> {
151151
this.envs = await this.persistentStorage.load();
152152
this.envs.forEach((e) => {
153-
e.hasLatestInfo = false;
153+
delete e.hasLatestInfo;
154154
});
155155
}
156156

src/test/pythonEnvironments/base/locators/composite/envsCollectionService.unit.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '../../../../../client/pythonEnvironments/base/locators/composite/envsCollectionCache';
2323
import { EnvsCollectionService } from '../../../../../client/pythonEnvironments/base/locators/composite/envsCollectionService';
2424
import { PythonEnvCollectionChangedEvent } from '../../../../../client/pythonEnvironments/base/watcher';
25+
import * as externalDependencies from '../../../../../client/pythonEnvironments/common/externalDependencies';
2526
import { noop } from '../../../../core';
2627
import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';
2728
import { SimpleLocator } from '../../common';
@@ -546,6 +547,9 @@ suite('Python envs locator - Environments Collection', async () => {
546547
const resolvedViaLocator = buildEnvInfo({ executable: 'Resolved via locator' });
547548
const cachedEnvs = getCachedEnvs();
548549
const env: PythonEnvLatestInfo = cachedEnvs[0];
550+
env.executable.ctime = 100;
551+
env.executable.mtime = 100;
552+
sinon.stub(externalDependencies, 'getFileInfo').resolves({ ctime: 100, mtime: 100 });
549553
env.hasLatestInfo = true; // Has complete info
550554
const parentLocator = new SimpleLocator([], {
551555
resolve: async (e: PythonEnvInfo) => {
@@ -565,6 +569,35 @@ suite('Python envs locator - Environments Collection', async () => {
565569
sinon.assert.calledOnce(reportInterpretersChangedStub);
566570
});
567571

572+
test('resolveEnv() uses underlying locator if cache does not have complete info for env', async () => {
573+
const cachedEnvs = getCachedEnvs();
574+
const env: PythonEnvLatestInfo = cachedEnvs[0];
575+
const resolvedViaLocator = buildEnvInfo({
576+
executable: env.executable.filename,
577+
sysPrefix: 'Resolved via locator',
578+
});
579+
env.executable.ctime = 101;
580+
env.executable.mtime = 90;
581+
sinon.stub(externalDependencies, 'getFileInfo').resolves({ ctime: 100, mtime: 100 });
582+
env.hasLatestInfo = true; // Has complete info
583+
const parentLocator = new SimpleLocator([], {
584+
resolve: async (e: PythonEnvInfo) => {
585+
if (env.executable.filename === e.executable.filename) {
586+
return resolvedViaLocator;
587+
}
588+
return undefined;
589+
},
590+
});
591+
const cache = await createCollectionCache({
592+
load: async () => cachedEnvs,
593+
store: async () => noop(),
594+
});
595+
collectionService = new EnvsCollectionService(cache, parentLocator);
596+
const resolved = await collectionService.resolveEnv(env.executable.filename);
597+
assertEnvEqual(resolved, resolvedViaLocator);
598+
sinon.assert.calledOnce(reportInterpretersChangedStub);
599+
});
600+
568601
test('resolveEnv() uses underlying locator if cache does not have complete info for env', async () => {
569602
const resolvedViaLocator = buildEnvInfo({ executable: 'Resolved via locator' });
570603
const cachedEnvs = getCachedEnvs();

0 commit comments

Comments
 (0)