Skip to content

Commit

Permalink
Correct dummy implementations and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Sep 22, 2020
1 parent 3126024 commit cdc339a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 8 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 @@ -94,6 +94,8 @@ async function resolveDifferencesInBackground(
if (!isEqual(oldEnv, merged)) {
didUpdate.fire({ old: oldEnv, new: merged });
seen[oldIndex] = merged;
} else {
const x = 2;
}
state.pending -= 1;
checkIfFinishedAndNotify(state, didUpdate);
Expand All @@ -115,10 +117,11 @@ function checkIfFinishedAndNotify(
}

export function mergeEnvironments(environment: PythonEnvInfo, other: PythonEnvInfo): PythonEnvInfo {
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 +134,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

0 comments on commit cdc339a

Please sign in to comment.