This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from ExecutableBookProject/myst_init
adding myst init command
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 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,32 @@ | ||
from pathlib import Path | ||
from subprocess import run, PIPE | ||
import pytest | ||
from jupyter_book.utils import init_myst_file | ||
|
||
|
||
def test_myst_init(tmpdir): | ||
"""Test adding myst metadata to text files.""" | ||
path = Path(tmpdir).joinpath("tmp.md").absolute() | ||
text = "TEST" | ||
with open(path, "w") as ff: | ||
ff.write(text) | ||
init_myst_file(path, kernel="python3") | ||
|
||
# Make sure it runs properly. Default kernel should be python3 | ||
new_text = path.read_text() | ||
assert "format_name: myst" in new_text | ||
assert "TEST" == new_text.strip().split("\n")[-1] | ||
assert "name: python3" in new_text | ||
|
||
# Make sure the CLI works too | ||
run(f"jb myst init {path} --kernel python3".split(), check=True, stdout=PIPE) | ||
|
||
# Non-existent kernel | ||
with pytest.raises(Exception) as err: | ||
init_myst_file(path, kernel="blah") | ||
assert "Did not find kernel: blah" in str(err) | ||
|
||
# Missing file | ||
with pytest.raises(Exception) as err: | ||
init_myst_file(path.joinpath("MISSING"), kernel="python3") | ||
assert "Markdown file not found:" in str(err) |
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