Skip to content

Commit

Permalink
fix magic errors not causing failure (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-treebeard authored Aug 18, 2022
1 parent 8fa88df commit f0d4475
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
- run: poetry build
- run: pip install 'pytest==7.1'
- run: pip install dist/*gz --force-reinstall
- run: pytest --nbmake tests/resources
- run: pytest --nbmake tests/resources/mock.ipynb
- run: pip install dist/*whl --force-reinstall
- run: pytest --nbmake tests/resources
- run: pytest --nbmake tests/resources/mock.ipynb
- run: pip install twine==4.0.1
- run: twine upload -r testpypi dist/* -u alex-treebeard-test -p ${{ secrets.TEST_PYPI_PASSWORD }}
105 changes: 104 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/nbmake/nb_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def execute(
async def apply_mocks(
cell: NotebookNode, cell_index: int, execute_reply: Dict[str, Any]
):
# https://github.com/treebeardtech/nbmake/issues/77
if any(o["output_type"] == "error" for o in cell["outputs"]):
execute_reply["content"]["status"] = "error"

if c.kc is None:
raise Exception("there is no kernelclient")
mocks: Dict[str, Any] = (
Expand Down
18 changes: 18 additions & 0 deletions tests/resources/empty.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
50 changes: 50 additions & 0 deletions tests/resources/magic_error.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1)\n",
"ax.plot([0, 1, 2], [0, 1, 2])\n",
"ax.set_xlabel(r\"$\\\\tau$\");"
]
}
],
"metadata": {
"interpreter": {
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
},
"kernelspec": {
"display_name": "Python 3.10.4 64-bit",
"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.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
12 changes: 12 additions & 0 deletions tests/test_nb_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,15 @@ def test_when_mock_then_succeeds(self, testdir2: Never):
run = NotebookRun(nb, 300)
res: NotebookResult = run.execute()
assert res.error == None

def test_when_magic_error_then_fails(self, testdir2: Never):
nb = Path(__file__).parent / "resources" / "magic_error.ipynb"
run = NotebookRun(nb, 300)
res: NotebookResult = run.execute()
assert res.error != None

def test_when_empty_then_succeeds(self, testdir2: Never):
nb = Path(__file__).parent / "resources" / "empty.ipynb"
run = NotebookRun(nb, 300)
res: NotebookResult = run.execute()
assert res.error is None

0 comments on commit f0d4475

Please sign in to comment.