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/common.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2023 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// Use clean in-memory blob store for tests.6process.env.JUPYTER_BLOBS_DB_FILE = "memory";78import { kernel as jupyter_kernel } from "../jupyter";910import { JupyterKernelInterface } from "@cocalc/frontend/jupyter/project-interface";11export type JupyterKernel = JupyterKernelInterface;1213import json from "json-stable-stringify";1415const DEBUG = !!process.env["DEBUG"];16if (DEBUG) {17console.log("DEBUG =", DEBUG);18}1920// We use custom kernels for testing, since faster to start.21// For example, we don't use matplotlib inline for testing (much) and22// using it greatly slows down startup.23export function custom_kernel_path() {24process.env.JUPYTER_PATH = `${__dirname}/jupyter`;25}26custom_kernel_path();2728export function default_kernel_path() {29process.env.JUPYTER_PATH = "/ext/jupyter";30}3132export function kernel(name: string, path?: string): JupyterKernelInterface {33if (path == null) {34path = "";35}36return jupyter_kernel({ name, verbose: DEBUG, path });37}3839export async function exec(k: JupyterKernel, code: string): Promise<string> {40return output(await k.execute_code_now({ code: code }));41}4243// String summary of key aspect of output, which is useful for testing.44export function output(v: any[]): string {45let s = "";46let x: any;47for (x of v) {48if (x.content == null) continue;49if (x.content.data != null) {50return json(x.content.data);51}52if (x.content.text != null) {53s += x.content.text;54}55if (x.content.ename != null) {56return json(x.content);57}58}59return s;60}616263