Path: blob/master/src/packages/jupyter/kernel/test/input.test.ts
1450 views
/*1Test interactive input, which uses the stdin channel23https://jupyter-client.readthedocs.io/en/stable/messaging.html456pnpm test `pwd`/input.test.ts7*/89import { getPythonKernel, closeKernels } from "./util";1011describe("test that interactive input throws an error if we do not provide a stdin function", () => {12let k;13it("get a python kernel", async () => {14k = await getPythonKernel("python-nostdin.ipynb");15});1617it("test without stdin", async () => {18const code = "a = input('a:')";19const v: any[] = [];20// we do not pass a stdin function as an option:21const output = k.execute_code({ code });22for await (const out of output.iter()) {23v.push(out);24}25expect(JSON.stringify(v)).toContain("StdinNotImplementedError");26});2728it("cleans up", () => {29k.close();30});31});3233describe("test interactive input", () => {34let k;35it("get a python kernel", async () => {36k = await getPythonKernel("python-stdin.ipynb");37});3839it("start some code running with stdin set and see it is called", async () => {40const code = "a = input('a:')";41const v: any[] = [];42const stdin = async (prompt: string, password: boolean) => {43v.push({ prompt, password });44return "bar";45};46const output = k.execute_code({ code, stdin });47for await (const _ of output.iter()) {48}49expect(v).toEqual([{ prompt: "a:", password: false }]);50});5152it("cleans up", () => {53k.close();54});55});5657afterAll(() => {58closeKernels();59});606162