Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/jupyter/stateless-api/execute.test.ts
1447 views
1
import { getPythonKernelName } from "../kernel/kernel-data";
2
import jupyterExecute from "./execute";
3
4
describe("test the jupyterExecute function", () => {
5
let kernel;
6
7
it(`gets a kernel name`, async () => {
8
kernel = await getPythonKernelName();
9
});
10
11
it("computes 2+3", async () => {
12
const outputs = await jupyterExecute({ kernel, input: "a=5; 2+3" });
13
expect(outputs).toEqual([{ data: { "text/plain": "5" } }]);
14
});
15
16
it("checks that its stateless, i.e., a is not defined", async () => {
17
const outputs = await jupyterExecute({ kernel, input: "print(a)" });
18
expect(JSON.stringify(outputs)).toContain("is not defined");
19
});
20
21
it("sets a via history", async () => {
22
const outputs = await jupyterExecute({
23
kernel,
24
input: "print(a**2)",
25
history: ["a=5"],
26
});
27
expect(outputs).toEqual([{ name: "stdout", text: "25\n" }]);
28
});
29
30
it("limits the output size", async () => {
31
const outputs = await jupyterExecute({
32
kernel,
33
input: "print('hi'); import sys; sys.stdout.flush(); print('x'*100)",
34
limits: { max_output_per_cell: 50 },
35
});
36
expect(outputs).toEqual([
37
{ name: "stdout", text: "hi\n" },
38
{
39
name: "stdout",
40
output_type: "stream",
41
text: [
42
"Output truncated since it exceeded the cell output limit of 50 characters",
43
],
44
},
45
]);
46
});
47
});
48
49
50