From 748c13b62eab5435c5c389ef396eba1d223a1ae8 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 12 Nov 2023 11:01:05 +0000 Subject: [PATCH 1/2] Add a test to reproduce #1131 --- tests/functional/others/test_active_cells.py | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/functional/others/test_active_cells.py b/tests/functional/others/test_active_cells.py index 29824194f..1403caf3e 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') From 9059531f0452fc08c17c88a69b5667f88d05ebf1 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 12 Nov 2023 11:04:40 +0000 Subject: [PATCH 2/2] Don't uncomment ipynb raw cells --- src/jupytext/cell_reader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jupytext/cell_reader.py b/src/jupytext/cell_reader.py index e4ea21c13..08b384cbc 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"