Skip to content

Commit 4a5113b

Browse files
author
Kartik Raj
committed
Generate tests properly
1 parent 796bae8 commit 4a5113b

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/test/pythonEnvironments/base/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { expect } from 'chai';
55
import * as path from 'path';
6-
import { Event } from 'vscode';
6+
import { Event, Uri } from 'vscode';
77
import { createDeferred, flattenIterator, iterable, mapToIterator } from '../../../client/common/utils/async';
88
import { getArchitecture } from '../../../client/common/utils/platform';
99
import { getVersionString } from '../../../client/common/utils/version';
@@ -35,6 +35,7 @@ export function createLocatedEnv(
3535
kind = PythonEnvKind.Unknown,
3636
exec: string | PythonExecutableInfo = 'python',
3737
distro: PythonDistroInfo = { org: '' },
38+
searchLocation?: Uri,
3839
): PythonEnvInfo {
3940
const location =
4041
locationStr === ''
@@ -57,6 +58,7 @@ export function createLocatedEnv(
5758
executable,
5859
location,
5960
version,
61+
searchLocation,
6062
});
6163
env.arch = getArchitecture();
6264
env.distro = distro;

src/test/pythonEnvironments/base/info/env.unit.test.ts

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

44
import * as assert from 'assert';
5+
import { Uri } from 'vscode';
56
import { Architecture } from '../../../../client/common/utils/platform';
67
import { parseVersionInfo } from '../../../../client/common/utils/version';
78
import { PythonEnvInfo, PythonDistroInfo, PythonEnvKind } from '../../../../client/pythonEnvironments/base/info';
@@ -11,6 +12,7 @@ import { createLocatedEnv } from '../common';
1112
suite('Environment helpers', () => {
1213
const name = 'my-env';
1314
const location = 'x/y/z/spam/';
15+
const searchLocation = 'x/y/z';
1416
const arch = Architecture.x64;
1517
const version = '3.8.1';
1618
const kind = PythonEnvKind.Venv;
@@ -28,44 +30,50 @@ suite('Environment helpers', () => {
2830
distro?: PythonDistroInfo;
2931
display?: string;
3032
location?: string;
33+
searchLocation?: string;
3134
}): PythonEnvInfo {
3235
const env = createLocatedEnv(
3336
info.location || '',
3437
info.version || '',
3538
info.kind || PythonEnvKind.Unknown,
3639
'python', // exec
3740
info.distro,
41+
info.searchLocation ? Uri.file(info.searchLocation) : undefined,
3842
);
3943
env.name = info.name || '';
4044
env.arch = info.arch || Architecture.Unknown;
4145
env.display = info.display;
4246
return env;
4347
}
44-
const tests: [PythonEnvInfo, string, string][] = [
45-
[getEnv({}), 'Python', 'Python'],
46-
[getEnv({ version, arch, name, kind, distro }), "Python 3.8.1 ('my-env')", "Python 3.8.1 ('my-env': venv)"],
47-
// without "suffix" info
48-
[getEnv({ version }), 'Python 3.8.1', 'Python 3.8.1'],
49-
[getEnv({ arch }), 'Python 64-bit', 'Python 64-bit'],
50-
[getEnv({ version, arch }), 'Python 3.8.1 64-bit', 'Python 3.8.1 64-bit'],
51-
// with "suffix" info
52-
[getEnv({ name }), "Python ('my-env')", "Python ('my-env')"],
53-
[getEnv({ kind }), 'Python', 'Python (venv)'],
54-
[getEnv({ name, kind }), "Python ('my-env')", "Python ('my-env': venv)"],
55-
// env.location is ignored.
56-
[getEnv({ location }), 'Python', 'Python'],
57-
[getEnv({ name, location }), "Python ('my-env')", "Python ('my-env')"],
58-
];
59-
tests.forEach(([env, expectedDisplay, expectedDetailedDisplay]) => {
48+
function testGenerator() {
49+
const tests: [PythonEnvInfo, string, string][] = [
50+
[getEnv({}), 'Python', 'Python'],
51+
[getEnv({ version, arch, name, kind, distro }), "Python 3.8.1 ('my-env')", "Python 3.8.1 ('my-env': venv)"],
52+
// without "suffix" info
53+
[getEnv({ version }), 'Python 3.8.1', 'Python 3.8.1'],
54+
[getEnv({ arch }), 'Python 64-bit', 'Python 64-bit'],
55+
[getEnv({ version, arch }), 'Python 3.8.1 64-bit', 'Python 3.8.1 64-bit'],
56+
// with "suffix" info
57+
[getEnv({ name }), "Python ('my-env')", "Python ('my-env')"],
58+
[getEnv({ kind }), 'Python', 'Python (venv)'],
59+
[getEnv({ name, kind }), "Python ('my-env')", "Python ('my-env': venv)"],
60+
// env.location is ignored.
61+
[getEnv({ location }), 'Python', 'Python'],
62+
[getEnv({ name, location }), "Python ('my-env')", "Python ('my-env')"],
63+
[getEnv({ name, location, searchLocation }), "Python ('my-env')", "Python ('my-env')"],
64+
];
65+
return tests;
66+
}
67+
testGenerator().forEach(([env, expectedDisplay, expectedDetailedDisplay]) => {
6068
test(`"${expectedDisplay}"`, () => {
6169
setEnvDisplayString(env);
6270

6371
assert.equal(env.display, expectedDisplay);
6472
assert.equal(env.detailedDisplayName, expectedDetailedDisplay);
6573
});
6674
});
67-
tests.forEach(([env1, _d1, display1], index1) => {
68-
tests.forEach(([env2, _d2, display2], index2) => {
75+
testGenerator().forEach(([env1, _d1, display1], index1) => {
76+
testGenerator().forEach(([env2, _d2, display2], index2) => {
6977
if (index1 === index2) {
7078
test(`"${display1}" === "${display2}"`, () => {
7179
assert.strictEqual(areEnvsDeepEqual(env1, env2), true);

0 commit comments

Comments
 (0)