Skip to content

Commit

Permalink
Add a test to document when pygment lexers appear in MyST Markdown (#778
Browse files Browse the repository at this point in the history
)

* New test to document when the ipython3 lexer appears in Myst MD files

* Version 1.11.2
  • Loading branch information
mwouts authored May 2, 2021
1 parent 0292460 commit ee468c8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Jupytext ChangeLog
==================

1.11.2 (2021-05-??)
1.11.2 (2021-05-02)
-------------------

**Changed**
Expand All @@ -14,6 +14,9 @@ Jupytext ChangeLog
cell metadata like `lines_to_next_cell` from the text file rather than ipynb ([#761](https://github.com/mwouts/jupytext/issues/761))
- The timestamp of the source file is not updated any more when the destination file is not in the pair ([#765](https://github.com/mwouts/jupytext/issues/765), [#767](https://github.com/mwouts/jupytext/issues/767))

**Added**
- A new test documents when the `ipython3` pygment lexer appears in MyST Markdown files ([#759](https://github.com/mwouts/jupytext/issues/759))


1.11.1 (2021-03-26)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.11.1+dev"
__version__ = "1.11.2"
57 changes: 57 additions & 0 deletions tests/test_ipynb_to_myst.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import unittest.mock as mock
from textwrap import dedent

Expand All @@ -7,6 +8,7 @@

import jupytext
from jupytext.cli import jupytext as jupytext_cli
from jupytext.compare import compare
from jupytext.formats import (
JupytextFormatError,
get_format_implementation,
Expand Down Expand Up @@ -193,3 +195,58 @@ def test_meaningfull_error_open_myst_missing(tmpdir):

with pytest.raises(HTTPError, match=PLEASE_INSTALL_MYST):
cm.get("notebook.md")


@requires_myst
@pytest.mark.parametrize("language_info", ["none", "std", "no_pygments_lexer"])
def test_myst_representation_same_cli_or_contents_manager(
tmpdir, cwd_tmpdir, notebook_with_outputs, language_info
):
"""This test gives some information on #759. As of Jupytext 1.11.1, in the MyST Markdown format,
the code cells have an ipython3 lexer when the notebook "language_info" metadata has "ipython3"
as the pygments_lexer. This information comes from the kernel and ATM it is not clear how the user
can choose to include it or not in the md file."""

nb = notebook_with_outputs
if language_info != "none":
nb["metadata"]["language_info"] = {
"codemirror_mode": {"name": "ipython", "version": 3},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3",
}
if language_info == "no_pygments_lexer":
del nb["metadata"]["language_info"]["pygments_lexer"]

# Writing the notebook with the Python API
text_api = jupytext.writes(nb, fmt="md:myst")

# How do code cells look like?
code_cells = set(
line for line in text_api.splitlines() if line.startswith("```{code-cell")
)

if language_info == "std":
assert code_cells == {"```{code-cell} ipython3"}
else:
assert code_cells == {"```{code-cell}"}

# We get the same file with the command line jupytext
tmpdir.mkdir("cli").join("notebook.ipynb").write(json.dumps(nb))
jupytext_cli(["--to", "md:myst", "cli/notebook.ipynb"])
text_cli = tmpdir.join("cli").join("notebook.md").read()

compare(text_cli, text_api)

# Or with the contents manager
cm = jupytext.TextFileContentsManager()
cm.formats = "ipynb,md:myst"
cm.root_dir = str(tmpdir.mkdir("contents_manager"))

cm.save(model=dict(content=nb, type="notebook"), path="notebook.ipynb")
text_cm = tmpdir.join("contents_manager").join("notebook.md").read()

compare(text_cm, text_api)

0 comments on commit ee468c8

Please sign in to comment.