From fbcb7762a70e596a1019c1200d7943afd22dda08 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sat, 7 Mar 2020 20:02:20 +0000 Subject: [PATCH] Add basic test and Travis CI (#51) * Add basic test * pre-commit fix * Add README badges --- .travis.yml | 22 ++++++------ .vscode/settings.json | 1 + README.md | 11 +++++- docs/use/index.md | 2 +- myst_nb/__init__.py | 5 +-- myst_nb/_static/mystnb.css | 2 +- myst_nb/parser.py | 2 +- setup.py | 4 +-- tests/notebooks/basic_failing.ipynb | 44 ++++++++++++++++++++++++ tests/notebooks/basic_run.ipynb | 53 +++++++++++++++++++++++++++++ tests/notebooks/basic_unrun.ipynb | 45 ++++++++++++++++++++++++ tests/test_basic.py | 23 +++++++++++++ tests/test_basic/test_basic.xml | 19 +++++++++++ 13 files changed, 214 insertions(+), 19 deletions(-) create mode 100644 tests/notebooks/basic_failing.ipynb create mode 100644 tests/notebooks/basic_run.ipynb create mode 100644 tests/notebooks/basic_unrun.ipynb create mode 100644 tests/test_basic.py create mode 100644 tests/test_basic/test_basic.xml diff --git a/.travis.yml b/.travis.yml index 1ff5b495..56b0e340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,12 @@ language: python cache: pip matrix: include: - - python: 3.5 - env: TEST_TYPE="pytest" - python: 3.6 env: TEST_TYPE="pytest" - python: 3.7 env: TEST_TYPE="pytest" + - python: 3.8 + env: TEST_TYPE="pytest" - python: 3.7 env: TEST_TYPE="pre-commit" install: @@ -22,10 +22,10 @@ install: pip install coveralls fi script: -# - | -# if [[ "$TEST_TYPE" == "pytest" ]]; then -# pytest -v --cov=myst_nb --cov-report= -# fi +- | + if [[ "$TEST_TYPE" == "pytest" ]]; then + pytest -v --cov=myst_nb --cov-report= + fi - | if [[ "$TEST_TYPE" == "pytest" ]]; then pytest -v @@ -34,8 +34,8 @@ script: if [[ "$TEST_TYPE" == "pre-commit" ]]; then pre-commit run --all-files || ( git status --short ; git diff ; exit 1 ) fi -# after_success: -# - | -# if [[ "$TEST_TYPE" == "pytest" ]]; then -# coveralls -# fi +after_success: +- | + if [[ "$TEST_TYPE" == "pytest" ]]; then + coveralls + fi diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ee89ab6..256ca0b6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,4 +13,5 @@ "python.linting.pylintEnabled": false, "python.linting.flake8Enabled": true, "python.linting.enabled": true, + "python.pythonPath": "/anaconda/envs/ebp/bin/python", } diff --git a/README.md b/README.md index ae74a34a..b62d6187 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # MyST-NB -[![Documentation Status](https://readthedocs.org/projects/myst-nb/badge/?version=latest)](https://myst-nb.readthedocs.io/en/latest/?badge=latest) +[![Build Status][travis-badge]][travis-link] +[![Coverage Status][coveralls-badge]][coveralls-link] +[![Documentation Status][rtd-badge]][rtd-link] A collection of tools for working with Jupyter Notebooks in Sphinx. @@ -14,3 +16,10 @@ It relies heavily on the [`MyST` parser](https://github.com/ExecutableBookProjec > use it! For more information, [see the MyST-NB documentation](https://myst-nb.readthedocs.io/en/latest/) + +[travis-link]: https://travis-ci.org/ExecutableBookProject/MyST-NB +[travis-badge]: https://travis-ci.org/ExecutableBookProject/MyST-NB.svg?branch=master +[rtd-badge]: https://readthedocs.org/projects/myst-nb/badge/?version=latest +[rtd-link]: https://myst-nb.readthedocs.io/en/latest/?badge=latest +[coveralls-badge]: https://coveralls.io/repos/github/ExecutableBookProject/MyST-NB/badge.svg +[coveralls-link]: https://coveralls.io/github/ExecutableBookProject/MyST-NB diff --git a/docs/use/index.md b/docs/use/index.md index bcd10a60..bf7a5ad3 100644 --- a/docs/use/index.md +++ b/docs/use/index.md @@ -7,4 +7,4 @@ in Sphinx with MyST-NB. basic interactive hiding -``` \ No newline at end of file +``` diff --git a/myst_nb/__init__.py b/myst_nb/__init__.py index f24337fe..e8ce2cdf 100644 --- a/myst_nb/__init__.py +++ b/myst_nb/__init__.py @@ -1,12 +1,13 @@ __version__ = "0.1.0" from docutils import nodes -from jupyter_sphinx.ast import ( +from jupyter_sphinx.ast import ( # noqa: F401 JupyterWidgetStateNode, JupyterWidgetViewNode, JupyterCell, ) -from ipywidgets import embed + +# from ipywidgets import embed from pathlib import Path from .parser import ( diff --git a/myst_nb/_static/mystnb.css b/myst_nb/_static/mystnb.css index f5a3c743..6b913cf6 100644 --- a/myst_nb/_static/mystnb.css +++ b/myst_nb/_static/mystnb.css @@ -96,4 +96,4 @@ div.cell_output table { } div.cell_output tbody tr:hover { background: rgba(66, 165, 245, 0.2); - } \ No newline at end of file + } diff --git a/myst_nb/parser.py b/myst_nb/parser.py index 862a0ba6..6571437d 100644 --- a/myst_nb/parser.py +++ b/myst_nb/parser.py @@ -75,7 +75,7 @@ def _render_cell(cell, renderer): # If a markdown cell, simply call the Myst parser and append children if cell["cell_type"] == "markdown": - document = Document(cell["source"], inc_front_matter=False) + document = Document.read(cell["source"], front_matter=False) # Check for tag-specific behavior because markdown isn't wrapped in a cell if "hide_input" in tags: container = nodes.container() diff --git a/setup.py b/setup.py index b402d98d..f04edf00 100644 --- a/setup.py +++ b/setup.py @@ -38,10 +38,10 @@ "Topic :: Text Processing :: Markup", ], keywords="markdown lexer parser development docutils sphinx", - python_requires=">=3.5", + python_requires=">=3.6", package_data={"myst_nb": ["_static/mystnb.css"]}, install_requires=[ - "myst-parser~=0.3", + "myst-parser~=0.4", "docutils>=0.15", "sphinx>=2,<3", "nbformat", diff --git a/tests/notebooks/basic_failing.ipynb b/tests/notebooks/basic_failing.ipynb new file mode 100644 index 00000000..16df1283 --- /dev/null +++ b/tests/notebooks/basic_failing.ipynb @@ -0,0 +1,44 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# a title\n", + "\n", + "some text\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "source": [ + "raise Exception('oopsie!')" + ], + "outputs": [] + } + ], + "metadata": { + "test_name": "notebook1", + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/notebooks/basic_run.ipynb b/tests/notebooks/basic_run.ipynb new file mode 100644 index 00000000..44fd69e1 --- /dev/null +++ b/tests/notebooks/basic_run.ipynb @@ -0,0 +1,53 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# a title\n", + "\n", + "some text\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "source": [ + "a=1\n", + "print(a)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ] + } + ], + "metadata": { + "test_name": "notebook1", + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/notebooks/basic_unrun.ipynb b/tests/notebooks/basic_unrun.ipynb new file mode 100644 index 00000000..7aae7db3 --- /dev/null +++ b/tests/notebooks/basic_unrun.ipynb @@ -0,0 +1,45 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# a title\n", + "\n", + "some text\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "source": [ + "a=1\n", + "print(a)" + ], + "outputs": [] + } + ], + "metadata": { + "test_name": "notebook1", + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 00000000..4dbbd44c --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,23 @@ +from pathlib import Path + +from docutils import nodes +from docutils.frontend import OptionParser +from docutils.parsers.rst import Parser as RSTParser +from docutils.utils import new_document + +from myst_nb.parser import NotebookParser + + +NB_DIR = Path(__file__).parent.joinpath("notebooks") + + +def get_document(source_path="notset") -> nodes.document: + settings = OptionParser(components=(RSTParser,)).get_default_values() + return new_document(source_path, settings=settings) + + +def test_basic(file_regression): + parser = NotebookParser() + document = get_document() + parser.parse(NB_DIR.joinpath("basic_run.ipynb").read_text(), document) + file_regression.check(document.pformat(), extension=".xml") diff --git a/tests/test_basic/test_basic.xml b/tests/test_basic/test_basic.xml new file mode 100644 index 00000000..17109b56 --- /dev/null +++ b/tests/test_basic/test_basic.xml @@ -0,0 +1,19 @@ + + + + + test_name + + notebook1 +
+ + a title + <paragraph> + some text + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block xml:space="preserve"> + a=1 + print(a) + <CellOutputNode classes="cell_output"> + <CellOutputBundleNode>