Skip to content

Commit 92a1f55

Browse files
authored
Fix unit tests (#15026)
* windowsStoreInterpreter.unit.test.ts * condaHelper.unit.test.ts
1 parent 69816a2 commit 92a1f55

File tree

2 files changed

+84
-93
lines changed

2 files changed

+84
-93
lines changed

src/test/pythonEnvironments/discovery/locators/condaHelper.unit.test.ts

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ suite('Conda binary is located correctly', () => {
257257
});
258258

259259
suite('Must find conda in well-known locations', () => {
260-
for (const condaDirName of ['Anaconda', 'anaconda', 'Miniconda', 'miniconda']) {
261-
for (const prefix of ['/usr/share', '/usr/local/share', '/opt', '/home/user', '/home/user/opt']) {
262-
const condaPath = `${prefix}/${condaDirName}`;
260+
const condaDirNames = ['Anaconda', 'anaconda', 'Miniconda', 'miniconda'];
263261

264-
test(`Must find conda in ${condaPath}`, async () => {
262+
condaDirNames.forEach((condaDirName) => {
263+
suite(`Must find conda in well-known locations on Linux with ${condaDirName} directory name`, () => {
264+
setup(() => {
265265
osType = platform.OSType.Linux;
266266
homeDir = '/home/user';
267267

@@ -283,23 +283,26 @@ suite('Conda binary is located correctly', () => {
283283
},
284284
},
285285
};
286+
});
286287

287-
const prefixDir = getFile(prefix) as Directory;
288-
prefixDir[condaDirName] = {
289-
bin: {
290-
conda: JSON.stringify(condaInfo('4.8.0')),
291-
},
292-
};
288+
['/usr/share', '/usr/local/share', '/opt', '/home/user', '/home/user/opt'].forEach((prefix) => {
289+
const condaPath = `${prefix}/${condaDirName}`;
293290

294-
await expectConda(`${condaPath}/bin/conda`);
295-
});
296-
}
291+
test(`Must find conda in ${condaPath}`, async () => {
292+
const prefixDir = getFile(prefix) as Directory;
293+
prefixDir[condaDirName] = {
294+
bin: {
295+
conda: JSON.stringify(condaInfo('4.8.0')),
296+
},
297+
};
297298

298-
// Drive letters are intentionally unusual to ascertain that locator doesn't hardcode paths.
299-
for (const prefix of ['D:\\ProgramData', 'E:\\Users\\user', 'F:\\Users\\user\\AppData\\Local\\Continuum']) {
300-
const condaPath = `${prefix}\\${condaDirName}`;
299+
await expectConda(`${condaPath}/bin/conda`);
300+
});
301+
});
302+
});
301303

302-
test(`Must find conda in ${condaPath}`, async () => {
304+
suite(`Must find conda in well-known locations on Windows with ${condaDirName} directory name`, () => {
305+
setup(() => {
303306
osType = platform.OSType.Windows;
304307
homeDir = 'E:\\Users\\user';
305308

@@ -330,18 +333,25 @@ suite('Conda binary is located correctly', () => {
330333
},
331334
},
332335
};
336+
});
333337

334-
const prefixDir = getFile(prefix) as Directory;
335-
prefixDir[condaDirName] = {
336-
Scripts: {
337-
'conda.exe': JSON.stringify(condaInfo('4.8.0')),
338-
},
339-
};
338+
// Drive letters are intentionally unusual to ascertain that locator doesn't hardcode paths.
339+
['D:\\ProgramData', 'E:\\Users\\user', 'F:\\Users\\user\\AppData\\Local\\Continuum'].forEach((prefix) => {
340+
const condaPath = `${prefix}\\${condaDirName}`;
341+
342+
test(`Must find conda in ${condaPath}`, async () => {
343+
const prefixDir = getFile(prefix) as Directory;
344+
prefixDir[condaDirName] = {
345+
Scripts: {
346+
'conda.exe': JSON.stringify(condaInfo('4.8.0')),
347+
},
348+
};
340349

341-
await expectConda(`${condaPath}\\Scripts\\conda.exe`);
350+
await expectConda(`${condaPath}\\Scripts\\conda.exe`);
351+
});
342352
});
343-
}
344-
}
353+
});
354+
});
345355
});
346356

347357
suite('Must find conda in environments.txt', () => {

src/test/pythonEnvironments/discovery/locators/windowsStoreInterpreter.unit.test.ts

Lines changed: 48 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,36 @@ suite('Interpreters - Windows Store Interpreter', () => {
6262
'C:\\Microsoft\\WindowsApps\\PythonSoftwareFoundation\\Python.exe',
6363
'C:\\microsoft\\WindowsApps\\PythonSoftwareFoundation\\Something\\Python.exe',
6464
];
65+
66+
async function isWindowsStoreInterpreter(interpreter: string) {
67+
return windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter);
68+
}
69+
70+
function isHiddenInterpreter(interpreter: string) {
71+
return windowsStoreInterpreter.isHiddenInterpreter(interpreter);
72+
}
73+
6574
for (const interpreter of windowsStoreInterpreters) {
66-
test(`${interpreter} must be identified as a windows store interpter`, async () => {
67-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter)).to.equal(true, 'Must be true');
75+
test(`${interpreter} must be identified as a Windows Store interpreter`, async () => {
76+
expect(await isWindowsStoreInterpreter(interpreter)).to.equal(true, 'Must be true');
6877
});
69-
test(`${interpreter.toLowerCase()} must be identified as a windows store interpter (ignoring case)`, async () => {
70-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter.toLowerCase())).to.equal(
71-
true,
72-
'Must be true',
73-
);
74-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter.toUpperCase())).to.equal(
75-
true,
76-
'Must be true',
77-
);
78+
79+
test(`${interpreter.toLowerCase()} must be identified as a Windows Store interpreter (lower case)`, async () => {
80+
expect(await isWindowsStoreInterpreter(interpreter.toLowerCase())).to.equal(true, 'Must be true');
81+
expect(await isWindowsStoreInterpreter(interpreter.toUpperCase())).to.equal(true, 'Must be true');
7882
});
79-
test(`D${interpreter.substring(
80-
1,
81-
)} must be identified as a windows store interpter (ignoring driver letter)`, async () => {
82-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(`D${interpreter.substring(1)}`)).to.equal(
83-
true,
84-
'Must be true',
85-
);
83+
84+
const otherDrive = `D${interpreter.substring(1)}`;
85+
test(`${otherDrive} must be identified as a Windows Store interpreter (ignoring driver letter)`, async () => {
86+
expect(await isWindowsStoreInterpreter(otherDrive)).to.equal(true, 'Must be true');
8687
});
87-
test(`${interpreter.replace(
88-
/\\/g,
89-
'/',
90-
)} must be identified as a windows store interpter (ignoring path separator)`, async () => {
91-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter.replace(/\\/g, '/'))).to.equal(
92-
true,
93-
'Must be true',
94-
);
88+
89+
const ignorePathSeparator = interpreter.replace(/\\/g, '/');
90+
test(`${ignorePathSeparator} must be identified as a Windows Store interpreter (ignoring path separator)`, async () => {
91+
expect(await isWindowsStoreInterpreter(ignorePathSeparator)).to.equal(true, 'Must be true');
9592
});
9693
}
94+
9795
const nonWindowsStoreInterpreters = [
9896
'..\\Program Filess\\WindowsApps\\Something\\Python.exe',
9997
'C:\\Program Filess\\WindowsApps\\Something\\Python.exe',
@@ -109,29 +107,18 @@ suite('Interpreters - Windows Store Interpreter', () => {
109107
'C:\\Apps\\Python.exe',
110108
];
111109
for (const interpreter of nonWindowsStoreInterpreters) {
112-
test(`${interpreter} must not be identified as a windows store interpter`, async () => {
113-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter)).to.equal(false, 'Must be false');
114-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter.replace(/\\/g, '/'))).to.equal(
115-
false,
116-
'Must be false',
117-
);
118-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter)).to.equal(false, 'Must be false');
119-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter.replace(/\\/g, '/'))).to.equal(
120-
false,
121-
'Must be false',
122-
);
123-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter.toLowerCase())).to.equal(
124-
false,
125-
'Must be false',
126-
);
127-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(interpreter.toUpperCase())).to.equal(
128-
false,
129-
'Must be false',
130-
);
131-
expect(await windowsStoreInterpreter.isWindowsStoreInterpreter(`D${interpreter.substring(1)}`)).to.equal(
132-
false,
133-
'Must be false',
134-
);
110+
test(`${interpreter} must not be identified as a Windows Store interpreter`, async () => {
111+
const ignorePathSeparator = interpreter.replace(/\\/g, '/');
112+
113+
expect(isHiddenInterpreter(interpreter)).to.equal(false, 'Must be false');
114+
expect(isHiddenInterpreter(ignorePathSeparator)).to.equal(false, 'Must be false');
115+
116+
expect(await isWindowsStoreInterpreter(interpreter)).to.equal(false, 'Must be false');
117+
expect(await isWindowsStoreInterpreter(ignorePathSeparator)).to.equal(false, 'Must be false');
118+
119+
expect(isHiddenInterpreter(interpreter.toLowerCase())).to.equal(false, 'Must be false');
120+
expect(await isWindowsStoreInterpreter(interpreter.toUpperCase())).to.equal(false, 'Must be false');
121+
expect(await isWindowsStoreInterpreter(`D${interpreter.substring(1)}`)).to.equal(false, 'Must be false');
135122
});
136123
}
137124
const windowsStoreHiddenInterpreters = [
@@ -141,33 +128,27 @@ suite('Interpreters - Windows Store Interpreter', () => {
141128
'C:\\microsoft\\WindowsApps\\PythonSoftwareFoundation\\Something\\Python.exe',
142129
];
143130
for (const interpreter of windowsStoreHiddenInterpreters) {
144-
test(`${interpreter} must be identified as a windows store (hidden) interpter`, () => {
145-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter)).to.equal(true, 'Must be true');
131+
test(`${interpreter} must be identified as a Windows Store (hidden) interpreter`, () => {
132+
expect(isHiddenInterpreter(interpreter)).to.equal(true, 'Must be true');
146133
});
147-
test(`${interpreter.toLowerCase()} must be identified as a windows store (hidden) interpter (ignoring case)`, () => {
148-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter.toLowerCase())).to.equal(
149-
true,
150-
'Must be true',
151-
);
152-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter.toUpperCase())).to.equal(
153-
true,
154-
'Must be true',
155-
);
134+
135+
test(`${interpreter.toLowerCase()} must be identified as a Windows Store (hidden) interpreter (ignoring case)`, () => {
136+
expect(isHiddenInterpreter(interpreter.toLowerCase())).to.equal(true, 'Must be true');
137+
expect(isHiddenInterpreter(interpreter.toUpperCase())).to.equal(true, 'Must be true');
156138
});
157-
test(`${interpreter} must be identified as a windows store (hidden) interpter (ignoring driver letter)`, () => {
158-
expect(windowsStoreInterpreter.isHiddenInterpreter(`D${interpreter.substring(1)}`)).to.equal(
159-
true,
160-
'Must be true',
161-
);
139+
140+
const otherDrive = `D${interpreter.substring(1)}`;
141+
test(`${otherDrive} must be identified as a Windows Store (hidden) interpreter (ignoring driver letter)`, () => {
142+
expect(isHiddenInterpreter(otherDrive)).to.equal(true, 'Must be true');
162143
});
163144
}
164145
const nonWindowsStoreHiddenInterpreters = [
165146
'C:\\Microsofts\\WindowsApps\\Something\\Python.exe',
166147
'C:\\Microsoft\\WindowsAppss\\Python.exe',
167148
];
168149
for (const interpreter of nonWindowsStoreHiddenInterpreters) {
169-
test(`${interpreter} must not be identified as a windows store (hidden) interpter`, () => {
170-
expect(windowsStoreInterpreter.isHiddenInterpreter(interpreter)).to.equal(false, 'Must be true');
150+
test(`${interpreter} must not be identified as a Windows Store (hidden) interpreter`, () => {
151+
expect(isHiddenInterpreter(interpreter)).to.equal(false, 'Must be true');
171152
});
172153
}
173154

0 commit comments

Comments
 (0)