Skip to content

Commit 83dd8b4

Browse files
author
Kartik Raj
committed
Correct dummy implementations and adjust tests
1 parent 3126024 commit 83dd8b4

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/client/pythonEnvironments/collection/environmentsReducer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { isEqual } from 'lodash';
4+
import { cloneDeep, isEqual } from 'lodash';
55
import { Event, EventEmitter } from 'vscode';
66
import { traceVerbose } from '../../common/logger';
77
import { areSameEnvironment, PythonEnvInfo, PythonEnvKind } from '../base/info';
@@ -115,10 +115,11 @@ function checkIfFinishedAndNotify(
115115
}
116116

117117
export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvInfo): PythonEnvInfo {
118+
const result = cloneDeep(environment);
118119
// Preserve type information.
119120
// Possible we identified environment as unknown, but a later provider has identified env type.
120121
if (environment.kind === PythonEnvKind.Unknown && other.kind && other.kind !== PythonEnvKind.Unknown) {
121-
environment.kind = other.kind;
122+
result.kind = other.kind;
122123
}
123124
const props: (keyof PythonEnvInfo)[] = [
124125
'version',
@@ -131,11 +132,11 @@ export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvIn
131132
'searchLocation',
132133
];
133134
props.forEach((prop) => {
134-
if (!environment[prop] && other[prop]) {
135+
if (!result[prop] && other[prop]) {
135136
// tslint:disable: no-any
136137
// eslint-disable-next-line @typescript-eslint/no-explicit-any
137-
(environment as any)[prop] = other[prop];
138+
(result as any)[prop] = other[prop];
138139
}
139140
});
140-
return environment;
141+
return result;
141142
}

src/test/pythonEnvironments/collection/environmentsReducer.unit.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { assert, expect } from 'chai';
5+
import { isEqual } from 'lodash';
56
import * as path from 'path';
67
import { EventEmitter } from 'vscode';
78
import { PythonEnvInfo, PythonEnvKind } from '../../../client/pythonEnvironments/base/info';
@@ -98,12 +99,14 @@ suite('Environments Reducer', () => {
9899

99100
// Assert
100101
const env12 = mergeEnvironments(env1, env2);
101-
const expectedUpdates = [
102-
{ old: env1, new: env12 },
103-
{ old: env12, new: mergeEnvironments(env12, env3) },
104-
null,
105-
];
106-
assert.deepEqual(expectedUpdates, onUpdatedEvents);
102+
const env123 = mergeEnvironments(env12, env3);
103+
const expectedUpdates: (PythonEnvUpdatedEvent | null)[] = [];
104+
if (isEqual(env12, env123)) {
105+
expectedUpdates.push({ old: env1, new: env12 }, null);
106+
} else {
107+
expectedUpdates.push({ old: env1, new: env12 }, { old: env12, new: env123 }, null);
108+
}
109+
assert.deepEqual(onUpdatedEvents, expectedUpdates);
107110
});
108111

109112
test('Updates to environments from the incoming iterator are passed on correctly followed by the null event', async () => {

0 commit comments

Comments
 (0)