Skip to content

Commit 6233049

Browse files
committed
Add more on nbval
1 parent 41f92e3 commit 6233049

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

03_ProcessData.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@
919919
],
920920
"metadata": {
921921
"kernelspec": {
922-
"display_name": "Python 3",
922+
"display_name": "Python [default]",
923923
"language": "python",
924924
"name": "python3"
925925
},

04_Testing.ipynb

+31-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
}
348348
},
349349
"source": [
350-
"# nbval\n",
350+
"## Testing Jupyter notebooks with nbval\n",
351351
"\n",
352352
"We first need to understand how a Jupyter notebook works. \n",
353353
"All the data is stored in a .json like format (organised key, data values)... this includes the results, code, and markdown.\n",
@@ -378,6 +378,35 @@
378378
"```"
379379
]
380380
},
381+
{
382+
"cell_type": "markdown",
383+
"metadata": {},
384+
"source": [
385+
"Since we have a timestamp in the notebook (`time.strftime('%H:%M:%S'))`) and the test is performed at a different time, the tests will fail. \n",
386+
"\n",
387+
"We can avoid this by providing a sanitizing file `sanitize.cfg`:\n",
388+
"<pre><code>\n",
389+
"[regex1]\n",
390+
"regex: \\d{1,2}/\\d{1,2}/\\d{2,4}\n",
391+
"replace: DATE-STAMP\n",
392+
"[regex2]\n",
393+
"regex: \\d{2}:\\d{2}:\\d{2}\n",
394+
"replace: TIME-STAMP\n",
395+
"</pre></code>\n",
396+
"\n",
397+
"This will identify time and data stamp like data in your notebooks. Then you can re run the test using:\n",
398+
"<pre><code>\n",
399+
"py.test --nbval demo.ipynb --sanitize-with sanitize_nb.cfg\n",
400+
"</pre></code>\n",
401+
"\n",
402+
"If you are only interested in verifying if your notebooks <strong>are broken or not</strong> (check for exceptions)\n",
403+
"you can use `--nbval-lax` which runs notebooks and checks for errors, but only compares the outputs of cells with a `#NBVAL_CHECK_OUTPUT` marker comment.\n",
404+
"<pre><code>\n",
405+
"$ py.test --nbval-lax classify-demo.ipynb\n",
406+
"</pre></code>\n",
407+
"\n"
408+
]
409+
},
381410
{
382411
"cell_type": "markdown",
383412
"metadata": {},
@@ -567,7 +596,7 @@
567596
],
568597
"metadata": {
569598
"kernelspec": {
570-
"display_name": "Python 3",
599+
"display_name": "Python [default]",
571600
"language": "python",
572601
"name": "python3"
573602
},

0 commit comments

Comments
 (0)