Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/pdealchemy/notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ def _save_source(_value: object) -> str:
label=save_label,
kind="success",
)
save_status = save_button.value
status_message = (
f"_Save status_: {save_status}"
if save_status is not None
else "_Edit the source and click Save equation file to persist changes._"
)
preview = _render_equation_block(
latex=_extract_first_latex_block(str(source_editor.value)),
name=name,
Expand All @@ -131,7 +125,7 @@ def _save_source(_value: object) -> str:
mo.md(f"### Inline equation source editor\n\n`{content}`"),
source_editor,
save_button,
mo.md(status_message),
mo.md("_Edit the source and click Save equation file to persist changes._"),
preview,
]
)
49 changes: 49 additions & 0 deletions tests/notebook/test_notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def click(self) -> None:
self.value = self._on_click(None)


class _NoValueReadButton:
def __init__(self, on_click: Any) -> None:
self._on_click = on_click

@property
def value(self) -> Any:
raise RuntimeError("Accessing button.value in creating cell is not allowed")

def click(self) -> Any:
return self._on_click(None)


class _FakeUi:
def code_editor(
self,
Expand Down Expand Up @@ -65,6 +77,30 @@ def vstack(blocks: list[object]) -> tuple[str, list[object]]:
return ("vstack", blocks)


class _NoValueReadUi(_FakeUi):
def button(
self,
*,
on_click: Any,
label: str,
kind: str,
) -> _NoValueReadButton:
_ = (label, kind)
return _NoValueReadButton(on_click)


class _NoValueReadMarimo:
ui = _NoValueReadUi()

@staticmethod
def md(text: str) -> tuple[str, str]:
return ("md", text)

@staticmethod
def vstack(blocks: list[object]) -> tuple[str, list[object]]:
return ("vstack", blocks)


def test_math_eq_renders_raw_latex(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(notebook_utils, "_load_marimo_module", _fake_marimo_module)

Expand Down Expand Up @@ -224,6 +260,19 @@ def test_math_eq_editor_rejects_missing_file(monkeypatch: pytest.MonkeyPatch) ->
assert "file not found" in rendered[1]


def test_math_eq_editor_does_not_access_button_value_in_creator_cell(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
equation_file = tmp_path / "equation.md"
equation_file.write_text("\\[\nS\n\\]", encoding="utf-8")
monkeypatch.setattr(notebook_utils, "_load_marimo_module", lambda: _NoValueReadMarimo)

rendered = notebook_utils.math_eq_editor(str(equation_file))

assert rendered[0] == "vstack"


def test_load_marimo_module_raises_config_error_when_missing(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down
Loading