Skip to content

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.

chore(convert): Move `_transform_sources` tests to snapshot-based tests (#5194)

Trevor Manz0628601be862
diff --git a/scripts/generate_ipynb_fixtures.py b/scripts/generate_ipynb_fixtures.py
index 7ed5c09e8e..ebc108d609 100644
--- a/scripts/generate_ipynb_fixtures.py
+++ b/scripts/generate_ipynb_fixtures.py
@@ -74,6 +74,34 @@ for i_1 in range(X_1.shape[0]):
],
)
+ create_notebook_fixture(
+ "duplicate_definitions_and_aug_assign",
+ [
+ "x = 1",
+ "x",
+ "x += 1",
+ "x",
+ ],
+ )
+
+ create_notebook_fixture(
+ "duplicate_definitions_read_before_write",
+ [
+ "x = 1",
+ "x",
+ "x; x = 2; x",
+ "x",
+ ],
+ )
+
+ create_notebook_fixture(
+ "duplicate_definitions_syntax_error",
+ [
+ "x ( b 2 d & !",
+ "x",
+ ],
+ )
+
if __name__ == "__main__":
main()
diff --git a/tests/_convert/ipynb_data/duplicate_definitions_and_aug_assign.ipynb b/tests/_convert/ipynb_data/duplicate_definitions_and_aug_assign.ipynb
new file mode 100644
index 0000000000..54283376ac
--- /dev/null
+++ b/tests/_convert/ipynb_data/duplicate_definitions_and_aug_assign.ipynb
@@ -0,0 +1,47 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x += 1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ }
+ ],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
\ No newline at end of file
diff --git a/tests/_convert/ipynb_data/duplicate_definitions_read_before_write.ipynb b/tests/_convert/ipynb_data/duplicate_definitions_read_before_write.ipynb
new file mode 100644
index 0000000000..d5f593fbcd
--- /dev/null
+++ b/tests/_convert/ipynb_data/duplicate_definitions_read_before_write.ipynb
@@ -0,0 +1,47 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x; x = 2; x"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ }
+ ],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
\ No newline at end of file
diff --git a/tests/_convert/ipynb_data/duplicate_definitions_syntax_error.ipynb b/tests/_convert/ipynb_data/duplicate_definitions_syntax_error.ipynb
new file mode 100644
index 0000000000..aaceea731f
--- /dev/null
+++ b/tests/_convert/ipynb_data/duplicate_definitions_syntax_error.ipynb
@@ -0,0 +1,27 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x ( b 2 d & !"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x"
+ ]
+ }
+ ],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
\ No newline at end of file
diff --git a/tests/_convert/snapshots/convert_duplicate_definitions_and_aug_assign.py.txt b/tests/_convert/snapshots/convert_duplicate_definitions_and_aug_assign.py.txt
new file mode 100644
index 0000000000..01f4649150
--- /dev/null
+++ b/tests/_convert/snapshots/convert_duplicate_definitions_and_aug_assign.py.txt
@@ -0,0 +1,31 @@
+import marimo
+
+app = marimo.App()
+
+
+def _():
+ x = 1
+ return (x,)
+
+
+def _(x):
+ x
+ return
+
+
+def _(x):
+ x_1 = x + 1
+ return (x_1,)
+
+
+def _(x_1):
+ x_1
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_convert/snapshots/convert_duplicate_definitions_read_before_write.py.txt b/tests/_convert/snapshots/convert_duplicate_definitions_read_before_write.py.txt
new file mode 100644
index 0000000000..4d7804c201
--- /dev/null
+++ b/tests/_convert/snapshots/convert_duplicate_definitions_read_before_write.py.txt
@@ -0,0 +1,33 @@
+import marimo
+
+app = marimo.App()
+
+
+def _():
+ x = 1
+ return (x,)
+
+
+def _(x):
+ x
+ return
+
+
+def _(x):
+ x
+ x_1 = 2
+ x_1
+ return (x_1,)
+
+
+def _(x_1):
+ x_1
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_convert/snapshots/convert_duplicate_definitions_syntax_error.py.txt b/tests/_convert/snapshots/convert_duplicate_definitions_syntax_error.py.txt
new file mode 100644
index 0000000000..af6594e572
--- /dev/null
+++ b/tests/_convert/snapshots/convert_duplicate_definitions_syntax_error.py.txt
@@ -0,0 +1,21 @@
+import marimo
+
+app = marimo.App()
+
+
+app._unparsable_cell(
+ r"""
+ x ( b 2 d & !
+ """,
+ name="_"
+)
+
+
+def _(x):
+ x
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_convert/test_ipynb.py b/tests/_convert/test_ipynb.py
index cc27a31625..03e7bf935a 100644
--- a/tests/_convert/test_ipynb.py
+++ b/tests/_convert/test_ipynb.py
@@ -6,7 +6,6 @@ from textwrap import dedent
import pytest
from marimo._convert.ipynb import (
- _transform_sources,
transform_add_marimo_import,
transform_cell_metadata,
transform_duplicate_definitions,
@@ -931,62 +930,3 @@ def test_transform_duplicate_definitions_numbered():
"df_3",
],
)
-
-
-def test_transform_duplicate_definitions_and_aug_assign() -> None:
- sources = dd(
- [
- "x = 1",
- "x",
- "x += 1",
- "x",
- ]
- )
- result = _transform_sources(sources, [{} for _ in sources])
- assert_sources_equal(
- result,
- [
- "x = 1",
- "x",
- "x_1 = x + 1",
- "x_1",
- ],
- )
-
-
-def test_transform_duplicate_definitions_read_before_write() -> None:
- sources = dd(
- [
- "x = 1",
- "x",
- "x; x = 2; x",
- "x",
- ]
- )
- result = _transform_sources(sources, [{} for _ in sources])
- assert_sources_equal(
- result,
- [
- "x = 1",
- "x",
- "x; x_1 = 2; x_1",
- "x_1",
- ],
- )
-
-
-def test_transform_duplicate_definitions_syntax_error() -> None:
- sources = dd(
- [
- "x ( b 2 d & !",
- "x",
- ]
- )
- result = _transform_sources(sources, [{} for _ in sources])
- assert_sources_equal(
- result,
- [
- "x ( b 2 d & !",
- "x",
- ],
- )