Skip to content

Commit

Permalink
unit test for handling magic command error
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Mar 28, 2024
1 parent 5127046 commit 5d69044
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
43 changes: 43 additions & 0 deletions papermill/tests/notebooks/line_magic_error.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%undefined-line-magic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Cell should not execute.\")"
]
}
],
"metadata": {
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
13 changes: 13 additions & 0 deletions papermill/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,19 @@ def test_system_exit(self):
self.assertEqual(nb.cells[1].outputs[0].evalue, '')
self.assertEqual(nb.cells[2].execution_count, None)

def test_line_magic_error(self):
notebook_name = 'line_magic_error.ipynb'
result_path = os.path.join(self.test_dir, f'output_{notebook_name}')
with self.assertRaises(PapermillExecutionError):
execute_notebook(get_notebook_path(notebook_name), result_path)
nb = load_notebook_node(result_path)
self.assertEqual(nb.cells[0].cell_type, "markdown")
self.assertRegex(nb.cells[0].source, r'^<span .*<a href="#papermill-error-cell".*In \[1\].*</span>$')
self.assertEqual(nb.cells[0].metadata["tags"], ["papermill-error-cell-tag"])
self.assertEqual(nb.cells[2].cell_type, "code")
self.assertEqual(nb.cells[2].execution_count, 1)
self.assertEqual(nb.cells[3].execution_count, None)


class TestNotebookValidation(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 5d69044

Please sign in to comment.