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