Skip to content

Commit a982f50

Browse files
committed
Add test of magics handling.
1 parent f88b438 commit a982f50

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_magics.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
3+
import nbformat
4+
5+
import pytest
6+
7+
from utils import build_nb
8+
9+
10+
pytest_plugins = "pytester"
11+
12+
@pytest.mark.parametrize("magic, expected_passes", [
13+
(r"%dirs", [True]),
14+
(r"%this_magic_does_not_exist", [False])
15+
])
16+
def test_magics(testdir, magic, expected_passes):
17+
# Setup notebook to test:
18+
sources = [
19+
# In [1]:
20+
magic,
21+
]
22+
nb = build_nb(sources)
23+
24+
# Write notebook to test dir
25+
nbformat.write(nb, os.path.join(
26+
str(testdir.tmpdir), 'test_magics.ipynb'))
27+
28+
# Run tests
29+
result = testdir.inline_run('--nbval-lax', '--current-env', '-s')
30+
reports = result.getreports('pytest_runtest_logreport')
31+
32+
# Setup and teardown of cells should have no issues:
33+
setup_teardown = [r for r in reports if r.when != 'call']
34+
for r in setup_teardown:
35+
assert r.passed
36+
37+
reports = [r for r in reports if r.when == 'call']
38+
39+
assert len(reports) == len(expected_passes)
40+
41+
for actual_report, expected_pass in zip(reports, expected_passes):
42+
assert actual_report.passed is expected_pass

0 commit comments

Comments
 (0)