Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix handling of bad magics #148

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ install:
fi
- pip install doit
- doit install_test_deps
- pip freeze

# command to run tests
script: doit test
33 changes: 33 additions & 0 deletions tests/test_magics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

import nbformat

import pytest

from utils import build_nb


pytest_plugins = "pytester"

@pytest.mark.parametrize("magic, expected_pass", [
(r"%dirs", True),
(r"%precision bad", False),
(r"%this_magic_does_not_exist", False)
])
def test_magics(testdir, magic, expected_pass):
nb = build_nb([
# In [1]:
magic,
])
nb_name = 'test_magics'
nbformat.write(nb, os.path.join(
str(testdir.tmpdir), nb_name+".ipynb"))

# using subprocess because otherwise second and subsequent tests always fail (some state left over somewhere in the jupyter stack)
result = testdir.runpytest_subprocess('--nbval-lax', '--current-env', '-s', '-v')

assert result.ret == (not expected_pass)

result.stdout.fnmatch_lines_random(
["*collected 1 item*",
"{nb_name}::ipynb::Cell 0 {result}".format(nb_name=nb_name, result="PASSED" if expected_pass else "FAILED")])