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