Skip to content

Commit 6ef1d3e

Browse files
committed
add nbdime test
1 parent 04383b2 commit 6ef1d3e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
install_requires = [
2424
'pytest >= 2.8',
25+
'pytest-mock',
2526
'jupyter_client',
2627
'nbformat',
2728
'ipykernel',

tests/test_nbdime_reporter.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
from utils import build_nb, add_expected_plaintext_outputs
3+
4+
import nbdime
5+
import nbformat
6+
import os
7+
8+
9+
def test_nbdime(testdir, mocker):
10+
11+
# Make a test notebook where output doesn't match input
12+
nb = build_nb(["1+1", "1+1"], mark_run=True)
13+
add_expected_plaintext_outputs(nb, ["2", "3"])
14+
# Write notebook to test dir
15+
filename = 'test_nbdime.ipynb'
16+
nbformat.write(nb, os.path.join(str(testdir.tmpdir), filename))
17+
18+
# patch the run_server function so that it doesn't actually
19+
# spawn a server and display the diff. But the diff is still
20+
# calculated.
21+
mocker.patch('nbdime.webapp.nbdiffweb.run_server')
22+
result = testdir.runpytest_inprocess('--nbval',
23+
'--nbval-current-env',
24+
'--nbdime',
25+
filename)
26+
# run_server() is only called if there is a discrepancy in the notebook.
27+
# so it should have been called in this case:
28+
nbdime.webapp.nbdiffweb.run_server.assert_called_once()
29+
30+
# note: this import must be AFTER the mocker.patch
31+
from nbval.nbdime_reporter import EXIT_TESTSFAILED
32+
assert result.ret == EXIT_TESTSFAILED

0 commit comments

Comments
 (0)