From 6ed8c7c672886e94122d73d868cd5ce0023c8ca0 Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Wed, 8 Apr 2020 16:08:12 -0700 Subject: [PATCH] updating tests for nested metadata --- .pre-commit-config.yaml | 2 +- myst_nb/parser.py | 4 +--- tests/test_parser.py | 34 ++++++++++++++++++++++++++++++---- tests/test_text_based.py | 13 ++++++++++++- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf54e771..01093e60 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ exclude: > \.vscode/settings\.json| tests/commonmark/commonmark\.json| .*\.xml| - tests/.*\.txt + tests/.*\.txt| )$ repos: diff --git a/myst_nb/parser.py b/myst_nb/parser.py index 7e8fa172..99670f0f 100644 --- a/myst_nb/parser.py +++ b/myst_nb/parser.py @@ -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 diff --git a/tests/test_parser.py b/tests/test_parser.py index 7f1860ac..199b97a2 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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 = { @@ -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 = { diff --git a/tests/test_text_based.py b/tests/test_text_based.py index ceb059be..f0989621 100644 --- a/tests/test_text_based.py +++ b/tests/test_text_based.py @@ -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")