-
Notifications
You must be signed in to change notification settings - Fork 294
/
kernelFinder.vscode.test.ts
88 lines (83 loc) · 3.52 KB
/
kernelFinder.vscode.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { assert } from 'chai';
import { Uri, workspace } from 'vscode';
import { PYTHON_LANGUAGE } from '../../../client/common/constants';
import { IKernelFinder } from '../../../client/datascience/kernel-launcher/types';
import { IExtensionTestApi } from '../../common';
import { initialize } from '../../initialize';
// tslint:disable: no-any no-invalid-this
suite('DataScience - Kernels Finder', () => {
let api: IExtensionTestApi;
let kernelFinder: IKernelFinder;
let resourceToUse: Uri;
suiteSetup(async () => {
api = await initialize();
kernelFinder = api.serviceContainer.get<IKernelFinder>(IKernelFinder);
resourceToUse = workspace.workspaceFolders![0].uri;
});
test('Can list all kernels', async () => {
const kernelSpecs = await kernelFinder.listKernelSpecs(resourceToUse);
assert.isArray(kernelSpecs);
assert.isAtLeast(kernelSpecs.length, 1);
});
test('No kernel returned if query is not provided', async () => {
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse);
assert.isUndefined(kernelSpec);
});
test('No kernel returned if no matching kernel found for language', async () => {
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
language_info: { name: 'foobar' },
orig_nbformat: 4
});
assert.isUndefined(kernelSpec);
});
test('No kernel returned if no matching kernel found', async () => {
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
kernelspec: { display_name: 'foobar', name: 'foobar' },
orig_nbformat: 4
});
assert.isUndefined(kernelSpec);
});
test('No kernel returned if kernelspec metadata not provided', async () => {
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
kernelspec: undefined,
orig_nbformat: 4
});
assert.isUndefined(kernelSpec);
});
test('Can find a Python kernel based on language', async () => {
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
language_info: { name: PYTHON_LANGUAGE },
orig_nbformat: 4
});
assert.ok(kernelSpec);
assert.equal(kernelSpec?.language, PYTHON_LANGUAGE);
});
test('Can find a Python kernel based on language (non-python-kernel)', async function () {
if (!process.env.VSC_JUPYTER_CI_RUN_NON_PYTHON_NB_TEST) {
return this.skip();
}
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
language_info: { name: 'julia' },
orig_nbformat: 4
});
assert.ok(kernelSpec);
assert.equal(kernelSpec?.language, 'julia');
});
test('Can find a Julia kernel based on kernelspec (non-python-kernel)', async function () {
if (!process.env.VSC_JUPYTER_CI_RUN_NON_PYTHON_NB_TEST) {
return this.skip();
}
const kernelSpecs = await kernelFinder.listKernelSpecs(resourceToUse);
const juliaKernelSpec = kernelSpecs.find((item) => item.language === 'julia');
assert.ok(juliaKernelSpec);
const kernelSpec = await kernelFinder.findKernelSpec(resourceToUse, {
kernelspec: juliaKernelSpec as any,
orig_nbformat: 4
});
assert.ok(kernelSpec);
assert.deepEqual(kernelSpec, juliaKernelSpec);
});
});