Skip to content

Commit 4c927f2

Browse files
committed
Stabilize scratchpad snapshots across Python versions
Two traceback-formatting differences slipped past `_normalize` and broke `test_ctx_create_cell_multiply_defined` on 3.10-3.12. First, the existing pointer regex required at least one `~`, so PEP 657 pure-caret underlines (`^^^^^^^^^^^^^^^^`, emitted by 3.11+ for expression spans) were never stripped; the new alternation matches those while keeping single-caret SyntaxError pointers intact (the classic ` ^`-style marker is present on every version, including 3.10, and the compile-error test asserts on it). Second, 3.13's collapsed-frames view of a multi-line `raise Foo(...)` keeps the trailing `)` on its own line after `_COLLAPSED_FRAMES_RE` elides the middle, whereas 3.10-3.12 don't show that line at all; the new `_RAISE_CLOSING_PAREN_RE` drops the lone closer so both worlds normalize to the same shape. The one affected snapshot is rewritten to match.
1 parent a5a12a8 commit 4c927f2

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/_server/test_scratchpad_integration.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,19 @@ def execute(self, code: str) -> list[str]:
280280
# Reduce the repo-prefix portion to a stable ``<marimo>`` marker so the
281281
# tail ``marimo/<subpkg>/<file>.py`` survives for readability.
282282
_MARIMO_SRC_RE = re.compile(r'\\"/[^"\\]*/(?=marimo/[^"\\]*\.py\\")')
283-
# Error-pointer line (Python 3.11+): indented `~+\^+~*` + trailing \n.
284-
# Absent on 3.10, so we strip it to make snapshots cross-version stable.
285-
_POINTER_RE = re.compile(r" +~+\^+~*\\n")
283+
# Error-pointer line (Python 3.11+): indented PEP 657 location underline.
284+
# Python emits this in two flavors: ``~~~^~~~`` (call-site, with tildes
285+
# flanking the carets) and ``^^^^`` (pure multi-caret spans, e.g. an
286+
# expression range). Absent on 3.10, so we strip both for cross-version
287+
# parity. Single-caret pointers (` ^`) come from the classic
288+
# SyntaxError source-position marker, which is present on all versions,
289+
# so we don't strip them.
290+
_POINTER_RE = re.compile(r" +(?:~+\^+~*|\^{2,})\\n")
291+
# Python 3.13's collapsed-frames view keeps the closing ``)`` on its own
292+
# line for multi-line ``raise Foo(...)`` after ``_COLLAPSED_FRAMES_RE``
293+
# elides the middle; 3.10–3.12 don't show it at all. Strip the lone
294+
# closer for cross-version parity.
295+
_RAISE_CLOSING_PAREN_RE = re.compile(r"(raise \w+\(\\n) +\)\\n")
286296
# Internal marimo frames (e.g. ``File "<tmp>", line 138, in execute_cell``)
287297
# that Py 3.10 shows but 3.11+ hides. Strip them so tests only match the
288298
# user-facing ``<module>`` frame.
@@ -313,6 +323,7 @@ def _normalize(body: str) -> list[str]:
313323
body = _POINTER_RE.sub("", body)
314324
body = _INTERNAL_FRAME_RE.sub("", body)
315325
body = _COLLAPSED_FRAMES_RE.sub("", body)
326+
body = _RAISE_CLOSING_PAREN_RE.sub(r"\1", body)
316327
body = _MARIMO_FRAME_LINENO_RE.sub(r"\1, line N", body)
317328
body = _AUTO_CELL_ID_RE.sub(r"\1'<cid>'", body)
318329
return body.splitlines()
@@ -643,7 +654,7 @@ def test_ctx_create_cell_multiply_defined(session: _Session) -> None:
643654
assert lines == snapshot(
644655
[
645656
"event: stderr",
646-
'data: {"data": "Traceback (most recent call last):\\n File \\"<marimo>/marimo/_runtime/executor.py\\", line N, in execute_cell_async\\n await eval(cell.body, glbls)\\n File \\"<tmp>\\", line 2, in <module>\\n async with cm.get_context() as ctx:\\n File \\"<marimo>/marimo/_code_mode/_context.py\\", line N, in __aexit__\\n self._dry_run_compile(ops)\\n File \\"<marimo>/marimo/_code_mode/_context.py\\", line N, in _dry_run_compile\\n raise RuntimeError(\\n )\\nRuntimeError: Multiply-defined names:\\n - \'x\' is already defined in cell \'cell_a\' (cell_a)\\n\\nTo skip validation, use: async with cm.get_context(skip_validation=True) as ctx\\n"}',
657+
'data: {"data": "Traceback (most recent call last):\\n File \\"<marimo>/marimo/_runtime/executor.py\\", line N, in execute_cell_async\\n await eval(cell.body, glbls)\\n File \\"<tmp>\\", line 2, in <module>\\n async with cm.get_context() as ctx:\\n File \\"<marimo>/marimo/_code_mode/_context.py\\", line N, in __aexit__\\n self._dry_run_compile(ops)\\n File \\"<marimo>/marimo/_code_mode/_context.py\\", line N, in _dry_run_compile\\n raise RuntimeError(\\nRuntimeError: Multiply-defined names:\\n - \'x\' is already defined in cell \'cell_a\' (cell_a)\\n\\nTo skip validation, use: async with cm.get_context(skip_validation=True) as ctx\\n"}',
647658
"",
648659
"event: done",
649660
'data: {"success": false, "output": {"mimetype": "text/plain", "data": ""}}',

0 commit comments

Comments
 (0)