Skip to content

Commit

Permalink
updating tests for nested metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Apr 8, 2020
1 parent aec986b commit 6ed8c7c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude: >
\.vscode/settings\.json|
tests/commonmark/commonmark\.json|
.*\.xml|
tests/.*\.txt
tests/.*\.txt|
)$
repos:
Expand Down
4 changes: 1 addition & 3 deletions myst_nb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ def parse_block(src, start_line):
# Note that myst_parser serialises dict/list like keys, when rendering to
# docutils docinfo. These could be read back with `json.loads`.
state.tokens = [
Token(
"front_matter", "", 0, content=({k: v for k, v in ntbk.metadata.items()}),
)
Token("front_matter", "", 0, content=({k: v for k, v in ntbk.metadata.items()}))
] + state.tokens

# If there are widgets, this will embed the state of all widgets in a script
Expand Down
34 changes: 30 additions & 4 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ def test_basic_run(sphinx_run, file_regression):
sphinx_run.build()
# print(sphinx_run.status())
assert sphinx_run.warnings() == ""
assert sphinx_run.app.env.metadata == {"basic_run": {"test_name": "notebook1"}}
assert set(sphinx_run.app.env.metadata["basic_run"].keys()) == {
"test_name",
"kernelspec",
"language_info",
}
assert sphinx_run.app.env.metadata["basic_run"]["test_name"] == "notebook1"
assert (
sphinx_run.app.env.metadata["basic_run"]["kernelspec"]
== '{"display_name": "Python 3", "language": "python", "name": "python3"}'
)
file_regression.check(sphinx_run.get_doctree().pformat(), extension=".xml")

filenames = {
Expand All @@ -20,11 +29,28 @@ def test_basic_run(sphinx_run, file_regression):
)
def test_complex_outputs(sphinx_run, file_regression):
sphinx_run.build()
# print(sphinx_run.status())
assert sphinx_run.warnings() == ""
assert sphinx_run.app.env.metadata == {
"complex_outputs": {"celltoolbar": "Edit Metadata", "hide_input": "False"}

assert set(sphinx_run.app.env.metadata["complex_outputs"].keys()) == {
"ipub",
"hide_input",
"nav_menu",
"celltoolbar",
"latex_envs",
"kernelspec",
"language_info",
"jupytext",
"toc",
"varInspector",
}
assert (
sphinx_run.app.env.metadata["complex_outputs"]["celltoolbar"] == "Edit Metadata"
)
assert sphinx_run.app.env.metadata["complex_outputs"]["hide_input"] == "False"
assert (
sphinx_run.app.env.metadata["complex_outputs"]["kernelspec"]
== '{"display_name": "Python 3", "language": "python", "name": "python3"}'
)
file_regression.check(sphinx_run.get_doctree().pformat(), extension=".xml")

filenames = {
Expand Down
13 changes: 12 additions & 1 deletion tests/test_text_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ def test_basic_run(sphinx_run, file_regression, check_nbs):
sphinx_run.build()
# print(sphinx_run.status())
assert sphinx_run.warnings() == ""
assert sphinx_run.app.env.metadata == {"basic_unrun": {"author": "Chris"}}
assert set(sphinx_run.app.env.metadata["basic_unrun"].keys()) == {
"jupytext",
"kernelspec",
"author",
"source_map",
"language_info",
}
assert sphinx_run.app.env.metadata["basic_unrun"]["author"] == "Chris"
assert (
sphinx_run.app.env.metadata["basic_unrun"]["kernelspec"]
== '{"display_name": "Python 3", "language": "python", "name": "python3"}'
)
file_regression.check(sphinx_run.get_nb(), check_fn=check_nbs, extension=".ipynb")
file_regression.check(sphinx_run.get_doctree().pformat(), extension=".xml")

0 comments on commit 6ed8c7c

Please sign in to comment.