Skip to content

Commit

Permalink
Do not uncomment raw ipynb cells (#1159)
Browse files Browse the repository at this point in the history
* Add a test to reproduce #1131
* Do not uncomment raw ipynb cells
  • Loading branch information
mwouts authored Nov 27, 2023
1 parent 405617f commit 9fac6f3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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

0 comments on commit 9fac6f3

Please sign in to comment.