Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not uncomment raw ipynb cells #1159

Merged
merged 2 commits into from
Nov 27, 2023
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
1 change: 1 addition & 0 deletions src/jupytext/cell_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ def find_cell_end(self, lines):
if self.metadata.get("active") == "":
del self.metadata["active"]
self.cell_type = "raw"
self.comment = ""
else:
self.cell_type = "code"

Expand Down
54 changes: 54 additions & 0 deletions tests/functional/others/test_active_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,60 @@ def test_active_cells_from_py_percent(
compare(text2, text)


def test_comments_work_in_active_cells_from_py_percent_1131(
text="""# %% tags=["active-py"]
# this is a comment
""",
):
nb = jupytext.reads(text, "py:percent")
assert nb.cells[0].cell_type == "raw"
assert nb.cells[0].source == "# this is a comment"

text2 = jupytext.writes(nb, "py:percent")
compare(text2, text)


def test_comments_work_in_active_cells_from_py_light_1131(
text="""# + tags=["active-py"]
# this is a comment
""",
):
nb = jupytext.reads(text, "py:light")
assert nb.cells[0].cell_type == "raw"
assert nb.cells[0].source == "# this is a comment"

text2 = jupytext.writes(nb, "py:light")
compare(text2, text)


def test_comments_plus_code_work_in_active_cells_from_py_percent_1131(
text="""# %% tags=["active-py"]
# this is a comment
1 + 1
""",
):
nb = jupytext.reads(text, "py:percent")
assert nb.cells[0].cell_type == "raw"
assert nb.cells[0].source == "# this is a comment\n1 + 1"

text2 = jupytext.writes(nb, "py:percent")
compare(text2, text)


def test_comments_plus_code_work_in_active_cells_from_py_light_1131(
text="""# + tags=["active-py"]
# this is a comment
1 + 1
""",
):
nb = jupytext.reads(text, "py:light")
assert nb.cells[0].cell_type == "raw"
assert nb.cells[0].source == "# this is a comment\n1 + 1"

text2 = jupytext.writes(nb, "py:light")
compare(text2, text)


def test_active_cells_from_py_light(
text="""# + active="py"
print('should only be displayed in py file')
Expand Down
Loading