-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
nb_to_myst
and round-trip conversion tests
- Loading branch information
1 parent
97b18de
commit 5d50424
Showing
4 changed files
with
114 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
language_info: | ||
name: python | ||
pygments_lexer: ipython3 | ||
nbformat: 4 | ||
nbformat_minor: 4 | ||
orphan: true | ||
--- | ||
|
||
a | ||
|
||
b | ||
c | ||
```{nb-code} ipython3 | ||
--- | ||
tags: | ||
- hide-code | ||
--- | ||
a = 1 | ||
print(a) | ||
``` | ||
|
||
c | ||
|
||
+++ {"tags": ["hide-cell"]} | ||
|
||
d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,20 @@ | ||
from textwrap import dedent | ||
import nbformat | ||
from myst_nb.convert import myst_to_nb | ||
|
||
|
||
def test_basic(file_regression): | ||
text = dedent( | ||
"""\ | ||
--- | ||
orphan: true | ||
--- | ||
from pathlib import Path | ||
|
||
a | ||
import nbformat | ||
from myst_nb.convert import myst_to_nb, nb_to_myst | ||
|
||
b | ||
c | ||
```{nb-cell} | ||
--- | ||
tags: ["hide-code"] | ||
--- | ||
a = 1 | ||
print(a) | ||
``` | ||
SOURCEDIR = Path(__file__).parent.joinpath("roundtrip") | ||
|
||
c | ||
|
||
+++ {"tags": ["hide-cell"]} | ||
def test_myst_to_nb(file_regression): | ||
text = SOURCEDIR.joinpath("basic.mystnb").read_text() | ||
notebook = myst_to_nb(text, directive="nb-code") | ||
file_regression.check( | ||
nbformat.writes(notebook), fullpath=SOURCEDIR.joinpath("basic.ipynb") | ||
) | ||
|
||
d | ||
|
||
""" | ||
) | ||
notebook = myst_to_nb(text, directive="nb-cell") | ||
file_regression.check(nbformat.writes(notebook), extension=".ipynb") | ||
def test_nb_to_myst(file_regression): | ||
text = SOURCEDIR.joinpath("basic.ipynb").read_text() | ||
output = nb_to_myst(nbformat.reads(text, 4), directive="nb-code") | ||
file_regression.check(output, fullpath=SOURCEDIR.joinpath("basic.mystnb")) |