A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
/* Copyright 2026 Marimo. All rights reserved. */
import { fireEvent, render, screen } from "@testing-library/react";
import { Provider } from "jotai";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import { MockRequestClient } from "@/__mocks__/requests";
import { Tracebacks } from "@/__mocks__/tracebacks";
import { cellId } from "@/__tests__/branded";
import { toggleBreakpoint } from "@/core/codemirror/cells/debugger-state";
import { TooltipProvider } from "@/components/ui/tooltip";
import { initialModeAtom } from "@/core/mode";
import { requestClientAtom } from "@/core/network/requests";
import { store } from "@/core/state/jotai";
import { renderHTML } from "@/plugins/core/RenderHTML";
import {
MarimoTracebackOutput,
replaceTracebackFilenames,
replaceTracebackPrefix,
} from "../MarimoTracebackOutput";
const cid = cellId("1");
vi.mock("@/core/config/feature-flag", async (importOriginal) => ({
...(await importOriginal<typeof import("@/core/config/feature-flag")>()),
getFeatureFlag: (flag: string) => flag === "debugger",
}));
vi.mock("@/core/codemirror/cells/debugger-state", async (importOriginal) => ({
...(await importOriginal<
typeof import("@/core/codemirror/cells/debugger-state")
>()),
toggleBreakpoint: vi.fn(),
}));
describe("traceback component", () => {
test("activates the breakpoint from the named button itself", () => {
render(
<Provider store={store}>
<TooltipProvider>
<MarimoTracebackOutput traceback={Tracebacks.raw} cellId={cid} />
</TooltipProvider>
</Provider>,
);
const buttons = screen.getAllByRole("button", {
name: "Toggle breakpoint",
});
fireEvent.click(buttons[0]);
expect(toggleBreakpoint).toHaveBeenCalledOnce();
});
beforeEach(() => {
vi.resetAllMocks();
store.set(initialModeAtom, "edit");
store.set(requestClientAtom, MockRequestClient.create());
});
test("extracts cell-link", () => {
const traceback = (
<Provider store={store}>
<TooltipProvider>
<MarimoTracebackOutput traceback={Tracebacks.raw} cellId={cid} />
</TooltipProvider>
</Provider>
);
const { unmount, getAllByRole } = render(traceback);
// Has traceback links
expect(getAllByRole("link")).toHaveLength(2);
// Check that the traceback links are parsed
expect(getAllByRole("link")[0].textContent).toContain(
"marimo://untitled#cell=",
);
expect(getAllByRole("link")[1].textContent).toContain(
"marimo://untitled#cell=",
);
unmount();
});
test("renames File to Cell for relevant lines", () => {
const traceback = (
<Provider store={store}>
<TooltipProvider>
<MarimoTracebackOutput traceback={Tracebacks.raw} cellId={cid} />
</TooltipProvider>
</Provider>
);
const { unmount, container } = render(traceback);
expect(container).not.toBeNull();
expect(Tracebacks.raw).not.toMatch(/Cell/);
expect(container.textContent).toMatch(/Cell/);
expect(Tracebacks.raw.match(/File/g)).toHaveLength(3);
expect(container?.textContent?.match(/File/g)).toHaveLength(1);
unmount();
});
});
describe("traceback replacement", () => {
beforeAll(() => {
store.set(initialModeAtom, "edit");
});
test("replaces File with Cell", () => {
const traceback = renderHTML({
html: Tracebacks.assertion,
additionalReplacements: [replaceTracebackPrefix],
});
const { unmount, container } = render(
<TooltipProvider>{traceback}</TooltipProvider>,
);
expect(container).not.toBeNull();
expect(Tracebacks.assertion).not.toMatch(/Cell/);
expect(container.textContent).toMatch(/Cell/);
expect(Tracebacks.assertion.match(/File/g)).toHaveLength(3);
// Only replaces the relevant File to Cell
expect(container?.textContent?.match(/File/g)).toHaveLength(2);
unmount();
});
test("renames filenames", () => {
const traceback = renderHTML({
html: Tracebacks.assertion,
additionalReplacements: [replaceTracebackFilenames],
});
const { unmount, getAllByRole, container } = render(
<TooltipProvider>{traceback}</TooltipProvider>,
);
expect(container).not.toBeNull();
// Has just traceback links
expect(getAllByRole("link")).toHaveLength(1);
// Check that the traceback links are parsed
expect(getAllByRole("link")[0].textContent).toContain(
"marimo://untitled#cell=",
);
expect(Tracebacks.assertion.match(/__marimo__cell_Hbol_/g)).toHaveLength(2);
// Still contains the string of the filename in the trace
expect(container?.textContent?.match(/__marimo__cell_Hbol_/g)).toHaveLength(
1,
);
unmount();
});
});