CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/jupyter/test/supported-kernels.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Do some tests with **all** of the kernels we officially support in CoCalc.
8
9
Obviously, this test file should take a while to run, since it starts
10
up many, many kernels, several of which are old Sage versions.
11
12
Also, sadly the tests are flakie... since some Jupyter kernels are flakie.
13
*/
14
15
import {} from "mocha";
16
import * as expect from "expect";
17
import * as common from "./common";
18
19
/* As of Aug, 2018:
20
21
$ jupyter kernelspec list
22
23
anaconda3 /ext/jupyter/kernels/anaconda3
24
anaconda5 /ext/jupyter/kernels/anaconda5
25
bash /ext/jupyter/kernels/bash
26
calysto_prolog /ext/jupyter/kernels/calysto_prolog
27
gap /ext/jupyter/kernels/gap
28
haskell /ext/jupyter/kernels/haskell
29
ir /ext/jupyter/kernels/ir
30
ir-sage /ext/jupyter/kernels/ir-sage
31
julia /ext/jupyter/kernels/julia
32
octave /ext/jupyter/kernels/octave
33
pari_jupyter /ext/jupyter/kernels/pari_jupyter
34
python2 /ext/jupyter/kernels/python2
35
python2-ubuntu /ext/jupyter/kernels/python2-ubuntu
36
python3 /ext/jupyter/kernels/python3
37
sage-8.1 /ext/jupyter/kernels/sage-8.1
38
sage-8.2 /ext/jupyter/kernels/sage-8.2
39
sage-develop /ext/jupyter/kernels/sage-develop
40
sagemath /ext/jupyter/kernels/sagemath
41
singular /ext/jupyter/kernels/singular
42
vpython /ext/jupyter/kernels/vpython
43
*/
44
45
// Set only to focus on only one of the kernels below.
46
const ONLY = "";
47
48
interface OneTest {
49
input: string;
50
output: string;
51
}
52
53
interface TestKernel {
54
kernel: string;
55
tests: OneTest[];
56
timeout?: number; // in ms
57
}
58
59
const EXEC_TESTS: TestKernel[] = [
60
{
61
kernel: "anaconda3",
62
tests: [
63
{
64
input: "print(1/3,4/3)",
65
output: "0.3333333333333333 1.3333333333333333\n",
66
},
67
],
68
},
69
{
70
kernel: "anaconda5",
71
tests: [
72
{
73
input: "print(1/3,4/3)",
74
output: "0.3333333333333333 1.3333333333333333\n",
75
},
76
],
77
},
78
{
79
kernel: "bash",
80
tests: [{ input: "echo 'foo bar'", output: "foo bar\n" }],
81
},
82
{
83
kernel: "gap",
84
tests: [{ input: "1/3 + 4/3", output: "5/3" }],
85
},
86
{
87
kernel: "haskell",
88
tests: [
89
{ input: "1/3 + 4/3", output: '{"text/plain":"1.6666666666666665"}' },
90
],
91
},
92
{
93
kernel: "ir",
94
tests: [
95
{
96
input: "1/3 + 4/3",
97
output:
98
'{"text/html":"1.66666666666667","text/latex":"1.66666666666667","text/markdown":"1.66666666666667","text/plain":"[1] 1.666667"}',
99
},
100
],
101
},
102
{
103
kernel: "ir-sage",
104
tests: [
105
{
106
input: "1/3 + 4/3",
107
output:
108
'{"text/html":"1.66666666666667","text/latex":"1.66666666666667","text/markdown":"1.66666666666667","text/plain":"[1] 1.666667"}',
109
},
110
],
111
},
112
{
113
kernel: "julia",
114
tests: [
115
{ input: "1/3 + 4/3", output: '{"text/plain":"1.6666666666666665"}' },
116
],
117
},
118
{
119
kernel: "octave",
120
tests: [{ input: "1/3 + 4/3", output: "ans = 1.6667\n" }],
121
},
122
{
123
kernel: "pari_jupyter",
124
tests: [{ input: "1/3 + 4/3", output: '{"text/plain":"5/3"}' }],
125
timeout: 20000,
126
},
127
{
128
kernel: "python2",
129
tests: [{ input: "print(1/3,4/3)", output: "(0, 1)\n" }],
130
},
131
{
132
kernel: "python2-ubuntu",
133
tests: [{ input: "print(1/3,4/3)", output: "(0, 1)\n" }],
134
},
135
{
136
kernel: "python3",
137
tests: [
138
{
139
input: "print(1/3,4/3)",
140
output: "0.3333333333333333 1.3333333333333333\n",
141
},
142
],
143
},
144
{
145
kernel: "sage-8.2",
146
tests: [{ input: "1/3 + 4/3", output: '{"text/plain":"5/3"}' }],
147
timeout: 60000,
148
},
149
{
150
kernel: "sage-8.3",
151
tests: [{ input: "1/3 + 4/3", output: '{"text/plain":"5/3"}' }],
152
timeout: 60000,
153
},
154
{
155
kernel: "sage-develop",
156
tests: [{ input: "1/3 + 4/3", output: '{"text/plain":"5/3"}' }],
157
timeout: 60000,
158
},
159
{
160
kernel: "sagemath",
161
tests: [{ input: "1/3 + 4/3", output: '{"text/plain":"5/3"}' }],
162
timeout: 60000,
163
},
164
{
165
/* Rant here: https://github.com/sagemathinc/cocalc/issues/3071 */
166
kernel: "singular",
167
tests: [
168
{
169
input: "2 + 3",
170
output:
171
'{"text/plain":"5\\n skipping text from `(` error at token `)`\\n"}',
172
},
173
],
174
timeout: 30000,
175
},
176
{
177
kernel: "vpython",
178
tests: [
179
{
180
input: "print(1/3,4/3)",
181
output: "0.3333333333333333 1.3333333333333333\n",
182
},
183
],
184
},
185
];
186
187
for (const test of EXEC_TESTS) {
188
if (ONLY && ONLY != test.kernel) {
189
continue;
190
}
191
describe(`tests the "${test.kernel}" kernel -- `, function () {
192
before(common.default_kernel_path);
193
after(common.custom_kernel_path);
194
this.timeout(test.timeout ? test.timeout : 20000);
195
196
let kernel: common.JupyterKernel;
197
198
it(`creates the "${test.kernel}" kernel`, function () {
199
kernel = common.kernel(test.kernel);
200
});
201
202
for (const { input, output } of test.tests) {
203
it(`evaluates "${input}"`, async function () {
204
expect(await common.exec(kernel, input)).toBe(output);
205
});
206
}
207
208
it(`closes the ${test.kernel} kernel`, function () {
209
kernel.close();
210
});
211
});
212
}
213
214