Skip to content

Commit

Permalink
WIP write a simpler test for go notebooks with %% shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 30, 2024
1 parent 79951c5 commit c933c88
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def cell_language(source, default_language, custom_cell_magics):
return lang, ""
elif line.startswith("%%"):
magic = line[2:]
if default_language == "go" and magic.strip() == "":
return None, None
if " " in magic:
lang, magic_args = magic.split(" ", 1)
else:
Expand Down
45 changes: 45 additions & 0 deletions tests/functional/simple_notebooks/test_read_simple_percent.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,48 @@ def test_cell_marker_has_same_indentation_as_code(
compare_notebooks(nb_actual, nb_expected)
text_actual = jupytext.writes(nb_actual, fmt="py:percent")
compare(text_actual, text)


def test_read_simple_gonb_cell_with_double_percent(
go_percent="""// ---
// jupyter:
// kernelspec:
// display_name: Go (gonb)
// language: go
// name: gonb
// ---
// %%
%%
fmt.Printf("Hello World!")
""",
):
"""The cell marker should have the same indentation as the first code line. See issue #562"""
nb = jupytext.reads(go_percent, fmt="go:percent")
assert len(nb.cells) == 1
(cell,) = nb.cells
assert cell.cell_type == "code", cell.cell_type
assert (
cell.source
== """%%
fmt.Printf("Hello World!")"""
)


def test_write_simple_gonb_cell_with_double_percent(
no_jupytext_version_number,
go_percent="""// ---
// jupyter:
// kernelspec:
// display_name: Go (gonb)
// language: go
// name: gonb
// ---
// %%
%%
fmt.Printf("Hello World!")
""",
):
"""The cell marker should have the same indentation as the first code line. See issue #562"""
nb = jupytext.reads(go_percent, fmt="go:percent")
go = jupytext.writes(nb, fmt="go:percent")
compare(go, go_percent)

0 comments on commit c933c88

Please sign in to comment.