From 734da8fded74d137fd3290d80eb945e9a8a27d6f Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 3 Sep 2021 07:27:54 -0700 Subject: [PATCH] Fix interpreter tests --- .../kernelFinder.vscode.test.ts | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/test/datascience/kernel-launcher/kernelFinder.vscode.test.ts b/src/test/datascience/kernel-launcher/kernelFinder.vscode.test.ts index cc412a577f71..7ba34982ff94 100644 --- a/src/test/datascience/kernel-launcher/kernelFinder.vscode.test.ts +++ b/src/test/datascience/kernel-launcher/kernelFinder.vscode.test.ts @@ -13,6 +13,7 @@ import { IInterpreterService } from '../../../client/interpreter/contracts'; import { IExtensionTestApi } from '../../common'; import { initialize } from '../../initialize'; import { traceInfo } from '../../../client/common/logger'; +import { spawnSync } from 'child_process'; /* eslint-disable @typescript-eslint/no-explicit-any, no-invalid-this */ suite('DataScience - Kernels Finder', () => { @@ -54,8 +55,21 @@ suite('DataScience - Kernels Finder', () => { name: PYTHON_LANGUAGE } }); - assert.ok(kernelSpec); - assert.equal(kernelSpec?.interpreter?.path, interpreter?.path, 'No interpreter found'); + if (!kernelSpec?.interpreter) { + throw new Error('Kernelspec & interpreter info should not be empty'); + } + const fullyQualifiedPythonPath = spawnSync(kernelSpec.interpreter.path, [ + '-c', + 'import sys;print(sys.executable)' + ]) + .stdout.toString() + .trim(); + + assert.isTrue( + kernelSpec?.interpreter?.path.toLowerCase() === interpreter?.path.toLocaleLowerCase() || + fullyQualifiedPythonPath.toLowerCase() === interpreter?.path.toLocaleLowerCase(), + `No interpreter found, kernelspec interpreter is ${kernelSpec?.interpreter?.path} & ${fullyQualifiedPythonPath}, but expected ${interpreter?.path}` + ); }); test('Interpreter kernel returned if kernelspec metadata not provided', async () => { const interpreter = await interpreterService.getActiveInterpreter(resourceToUse); @@ -66,8 +80,21 @@ suite('DataScience - Kernels Finder', () => { name: PYTHON_LANGUAGE } }); - assert.ok(kernelSpec); - assert.equal(kernelSpec?.interpreter?.path, interpreter?.path, 'No interpreter found'); + if (!kernelSpec?.interpreter) { + throw new Error('Kernelspec & interpreter info should not be empty'); + } + const fullyQualifiedPythonPath = spawnSync(kernelSpec.interpreter.path, [ + '-c', + 'import sys;print(sys.executable)' + ]) + .stdout.toString() + .trim(); + + assert.isTrue( + kernelSpec?.interpreter?.path.toLowerCase() === interpreter?.path.toLocaleLowerCase() || + fullyQualifiedPythonPath.toLowerCase() === interpreter?.path.toLocaleLowerCase(), + `No interpreter found, kernelspec interpreter is ${kernelSpec?.interpreter?.path} & ${fullyQualifiedPythonPath}, but expected ${interpreter?.path}` + ); }); test('Can find a Python kernel based on language', async () => { const kernelSpec = await kernelFinder.findKernel(resourceToUse, {