Skip to content

Commit

Permalink
Restore tests on Python 3.8
Browse files Browse the repository at this point in the history
Access to exception message with str(info.value)
Cf. pytest-dev/pytest#5528

Fixes #269
  • Loading branch information
mwouts committed Jun 30, 2019
1 parent 874072e commit 7ec3769
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -11,6 +11,9 @@ matrix:
- python: 3.7
dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069)
sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069)
- python: 3.8-dev
dist: xenial
sudo: required

install:
# We use conda in order to install pandoc
Expand Down
22 changes: 11 additions & 11 deletions tests/test_cli.py
Expand Up @@ -141,7 +141,7 @@ def test_error_not_notebook_ext_input(tmpdir, capsys):
with pytest.raises(JupytextFormatError) as info:
jupytext([tmp_file, '--to', 'py'])

assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info)
assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info.value)


@pytest.fixture
Expand All @@ -163,14 +163,14 @@ def test_error_not_notebook_ext_to(tmp_ipynb):
with pytest.raises(JupytextFormatError) as info:
jupytext([tmp_ipynb, '--to', 'ext'])

assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info)
assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info.value)


def test_error_not_notebook_ext_output(tmp_ipynb, tmpdir):
with pytest.raises(JupytextFormatError) as info:
jupytext([tmp_ipynb, '-o', str(tmpdir.join('not.ext'))])

assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info)
assert "Extension '.ext' is not a notebook extension. Please use one of" in str(info.value)


def test_error_not_same_ext(tmp_ipynb, tmpdir):
Expand All @@ -184,35 +184,35 @@ def test_error_no_action(tmp_ipynb):
with pytest.raises(ValueError) as info:
jupytext([tmp_ipynb])

assert "Please select an action" in str(info)
assert "Please select an action" in str(info.value)


def test_error_update_not_ipynb(tmp_py):
with pytest.raises(ValueError) as info:
jupytext([tmp_py, '--to', 'py', '--update'])

assert '--update is only for ipynb files' in str(info)
assert '--update is only for ipynb files' in str(info.value)


def test_error_multiple_input(tmp_ipynb):
with pytest.raises(ValueError) as info:
jupytext([tmp_ipynb, tmp_ipynb, '--to', 'py', '-o', 'notebook.py'])

assert 'Please input a single notebook when using --output' in str(info)
assert 'Please input a single notebook when using --output' in str(info.value)


def test_error_opt_missing_equal(tmp_ipynb):
with pytest.raises(ValueError) as info:
jupytext([tmp_ipynb, '--to', 'py', '--opt', 'missing_equal'])

assert 'key=value' in str(info)
assert 'key=value' in str(info.value)


def test_error_unknown_opt(tmp_ipynb):
with pytest.raises(ValueError) as info:
jupytext([tmp_ipynb, '--to', 'py', '--opt', 'unknown=true'])

assert 'is not a valid format option' in str(info)
assert 'is not a valid format option' in str(info.value)


def test_combine_same_version_ok(tmpdir):
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_combine_lower_version_raises(tmpdir):
with pytest.raises(ValueError) as info:
jupytext([tmp_nbpy, '--to', 'ipynb', '--update'])

assert 'Please remove one or the other file' in str(info)
assert 'Please remove one or the other file' in str(info.value)


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py'))
Expand Down Expand Up @@ -630,7 +630,7 @@ def test_sync(nb_file, tmpdir):
# Test that sync fails when notebook is not paired
with pytest.raises(ValueError) as info:
jupytext(['--sync', tmp_ipynb])
assert 'is not a paired notebook' in str(info)
assert 'is not a paired notebook' in str(info.value)

# Now with a pairing information
nb.metadata.setdefault('jupytext', {})['formats'] = 'py,Rmd,ipynb'
Expand Down Expand Up @@ -681,7 +681,7 @@ def test_sync_pandoc(nb_file, tmpdir):
# Test that sync fails when notebook is not paired
with pytest.raises(ValueError) as info:
jupytext(['--sync', tmp_ipynb])
assert 'is not a paired notebook' in str(info)
assert 'is not a paired notebook' in str(info.value)

# Now with a pairing information
nb.metadata.setdefault('jupytext', {})['formats'] = 'ipynb,md:pandoc'
Expand Down

0 comments on commit 7ec3769

Please sign in to comment.