Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/jupyter/test/payload.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Test payload shell message.7*/89import {} from "mocha";10import * as expect from "expect";11import * as common from "./common";12import { startswith, getIn } from "@cocalc/util/misc";1314describe("create python2 kernel and do evals with and without payloads -- ", async function () {15this.timeout(5000);1617const kernel: common.JupyterKernel = common.kernel("test-python2");1819it("does an eval with no payload", async function () {20const result: any[] = await kernel.execute_code_now({21code: "2+3",22});23for (const x of result) {24if (getIn(x, ["content", "payload"], []).length > 0) {25throw Error("there should not be any payloads");26}27}28});2930it("does an eval with a payload (requires internet)", async function () {31const result: any[] = await kernel.execute_code_now({32code:33"%load https://matplotlib.org/mpl_examples/showcase/integral_demo.py",34});35for (const x of result) {36let v;37if ((v = getIn(x, ["content", "payload"], [])).length > 0) {38const s =39'# %load https://matplotlib.org/mpl_examples/showcase/integral_demo.py\n"""\nPlot demonstrating';40expect(v.length).toBe(1);41expect(startswith(v[0].text, s)).toBe(true);42return;43}44}45});4647return it("closes the kernel", function () {48kernel.close();49});50});515253