Skip to content

Commit

Permalink
Add basic test and Travis CI (#51)
Browse files Browse the repository at this point in the history
* Add basic test
* pre-commit fix
* Add README badges
  • Loading branch information
chrisjsewell committed Mar 7, 2020
1 parent 51e97a2 commit fbcb776
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 19 deletions.
22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/anaconda/envs/ebp/bin/python",
}
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/use/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ in Sphinx with MyST-NB.
basic
interactive
hiding
```
```
5 changes: 3 additions & 2 deletions myst_nb/__init__.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion myst_nb/_static/mystnb.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ div.cell_output table {
}
div.cell_output tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
}
2 changes: 1 addition & 1 deletion myst_nb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions tests/notebooks/basic_failing.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
53 changes: 53 additions & 0 deletions tests/notebooks/basic_run.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
45 changes: 45 additions & 0 deletions tests/notebooks/basic_unrun.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -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")
19 changes: 19 additions & 0 deletions tests/test_basic/test_basic.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<document source="notset">
<docinfo>
<field>
<field_name>
test_name
<field_body>
notebook1
<section ids="a-title" names="a\ title">
<title>
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>

0 comments on commit fbcb776

Please sign in to comment.