diff --git a/src/jupytext/cell_reader.py b/src/jupytext/cell_reader.py index e4ea21c1..08b384cb 100644 --- a/src/jupytext/cell_reader.py +++ b/src/jupytext/cell_reader.py @@ -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" diff --git a/tests/functional/others/test_active_cells.py b/tests/functional/others/test_active_cells.py index 29824194..1403caf3 100644 --- a/tests/functional/others/test_active_cells.py +++ b/tests/functional/others/test_active_cells.py @@ -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')