diff --git a/src/pdealchemy/notebook_utils.py b/src/pdealchemy/notebook_utils.py index 9307584..a5e3539 100644 --- a/src/pdealchemy/notebook_utils.py +++ b/src/pdealchemy/notebook_utils.py @@ -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, @@ -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, ] ) diff --git a/tests/notebook/test_notebook_utils.py b/tests/notebook/test_notebook_utils.py index ade2d3f..949ae1b 100644 --- a/tests/notebook/test_notebook_utils.py +++ b/tests/notebook/test_notebook_utils.py @@ -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, @@ -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) @@ -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: