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/payload.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
Test payload shell message.
8
*/
9
10
import {} from "mocha";
11
import * as expect from "expect";
12
import * as common from "./common";
13
import { startswith, getIn } from "@cocalc/util/misc";
14
15
describe("create python2 kernel and do evals with and without payloads -- ", async function () {
16
this.timeout(5000);
17
18
const kernel: common.JupyterKernel = common.kernel("test-python2");
19
20
it("does an eval with no payload", async function () {
21
const result: any[] = await kernel.execute_code_now({
22
code: "2+3",
23
});
24
for (const x of result) {
25
if (getIn(x, ["content", "payload"], []).length > 0) {
26
throw Error("there should not be any payloads");
27
}
28
}
29
});
30
31
it("does an eval with a payload (requires internet)", async function () {
32
const result: any[] = await kernel.execute_code_now({
33
code:
34
"%load https://matplotlib.org/mpl_examples/showcase/integral_demo.py",
35
});
36
for (const x of result) {
37
let v;
38
if ((v = getIn(x, ["content", "payload"], [])).length > 0) {
39
const s =
40
'# %load https://matplotlib.org/mpl_examples/showcase/integral_demo.py\n"""\nPlot demonstrating';
41
expect(v.length).toBe(1);
42
expect(startswith(v[0].text, s)).toBe(true);
43
return;
44
}
45
}
46
});
47
48
return it("closes the kernel", function () {
49
kernel.close();
50
});
51
});
52
53