Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correct dummy implementations and adjust tests
  • Loading branch information
Kartik Raj
Kartik Raj committed Sep 22, 2020
commit 1f00f38040c7ade633c44c0d8aabd065addaaa48
11 changes: 6 additions & 5 deletions src/client/pythonEnvironments/collection/environmentsReducer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { isEqual } from 'lodash';
import { cloneDeep, isEqual } from 'lodash';
import { Event, EventEmitter } from 'vscode';
import { traceVerbose } from '../../common/logger';
import { areSameEnvironment, PythonEnvInfo, PythonEnvKind } from '../base/info';
Expand Down Expand Up @@ -115,10 +115,11 @@ function checkIfFinishedAndNotify(
}

export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvInfo): PythonEnvInfo {
Comment thread
ericsnowcurrently marked this conversation as resolved.
Comment thread
ericsnowcurrently marked this conversation as resolved.
const result = cloneDeep(environment);
// Preserve type information.
// Possible we identified environment as unknown, but a later provider has identified env type.
if (environment.kind === PythonEnvKind.Unknown && other.kind && other.kind !== PythonEnvKind.Unknown) {
environment.kind = other.kind;
result.kind = other.kind;
}
const props: (keyof PythonEnvInfo)[] = [
'version',
Expand All @@ -131,11 +132,11 @@ export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvIn
'searchLocation',
];
props.forEach((prop) => {
if (!environment[prop] && other[prop]) {
if (!result[prop] && other[prop]) {
// tslint:disable: no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(environment as any)[prop] = other[prop];
(result as any)[prop] = other[prop];
}
});
return environment;
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

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

// Assert
const env12 = mergeEnvironments(env1, env2);
const expectedUpdates = [
{ old: env1, new: env12 },
{ old: env12, new: mergeEnvironments(env12, env3) },
null,
];
assert.deepEqual(expectedUpdates, onUpdatedEvents);
const env123 = mergeEnvironments(env12, env3);
const expectedUpdates: (PythonEnvUpdatedEvent | null)[] = [];
if (isEqual(env12, env123)) {
expectedUpdates.push({ old: env1, new: env12 }, null);
} else {
expectedUpdates.push({ old: env1, new: env12 }, { old: env12, new: env123 }, null);
}
assert.deepEqual(onUpdatedEvents, expectedUpdates);
});

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