Skip to content

Commit

Permalink
Merge pull request #56 from minrk/pytest
Browse files Browse the repository at this point in the history
run tests with pytest
  • Loading branch information
takluyver committed Oct 7, 2016
2 parents 244c83c + 2926ba0 commit f761e7e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 56 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ build
dist
_build
docs/man/*.gz
docs/source/api/generated
docs/source/config/options
docs/source/interactive/magics-generated.txt
docs/gh-pages
IPython/html/notebook/static/mathjax
IPython/html/static/style/*.map
.cache
*.py[co]
__pycache__
*.egg-info
Expand Down
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: python
python:
- nightly
- 3.5
- 3.4
- 3.3
Expand All @@ -10,6 +11,10 @@ install:
- pip install . codecov
- pip install nbformat[test]
script:
- nosetests --with-coverage --cover-package=nbformat nbformat
- py.test -v --cov nbformat nbformat
after_success:
- codecov
matrix:
allow_failures:
- python: "nightly"

3 changes: 3 additions & 0 deletions nbformat/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
try:
# Python 3
algorithms = hashlib.algorithms_guaranteed
# shake algorithms in py36 are not compatible with hmac
# due to required length argument in digests
algorithms = [ a for a in algorithms if not a.startswith('shake_') ]
except AttributeError:
algorithms = hashlib.algorithms

Expand Down
6 changes: 2 additions & 4 deletions nbformat/v4/tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
import copy

import nose.tools as nt

from nbformat import validate
from .. import convert

Expand Down Expand Up @@ -40,7 +38,7 @@ def test_upgrade_heading():
),
]:
upgraded = convert.upgrade_cell(v3cell)
nt.assert_equal(upgraded, expected)
assert upgraded == expected

def test_downgrade_heading():
v3h = v3.new_heading_cell
Expand Down Expand Up @@ -69,4 +67,4 @@ def test_downgrade_heading():
),
]:
downgraded = convert.downgrade_cell(v4cell)
nt.assert_equal(downgraded, expected)
assert downgraded == expected
60 changes: 29 additions & 31 deletions nbformat/v4/tests/test_nbbase.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding: utf-8
"""Tests for the Python API for composing notebook elements"""

import nose.tools as nt

from nbformat.validator import isvalid, validate, ValidationError
from ..nbbase import (
NotebookNode, nbformat,
Expand All @@ -12,46 +10,46 @@

def test_empty_notebook():
nb = new_notebook()
nt.assert_equal(nb.cells, [])
nt.assert_equal(nb.metadata, NotebookNode())
nt.assert_equal(nb.nbformat, nbformat)
assert nb.cells == []
assert nb.metadata == NotebookNode()
assert nb.nbformat == nbformat

def test_empty_markdown_cell():
cell = new_markdown_cell()
nt.assert_equal(cell.cell_type, 'markdown')
nt.assert_equal(cell.source, '')
assert cell.cell_type == 'markdown'
assert cell.source == ''

def test_markdown_cell():
cell = new_markdown_cell(u'* Søme markdown')
nt.assert_equal(cell.source, u'* Søme markdown')
assert cell.source == u'* Søme markdown'

def test_empty_raw_cell():
cell = new_raw_cell()
nt.assert_equal(cell.cell_type, u'raw')
nt.assert_equal(cell.source, '')
assert cell.cell_type == u'raw'
assert cell.source == ''

def test_raw_cell():
cell = new_raw_cell('hi')
nt.assert_equal(cell.source, u'hi')
assert cell.source == u'hi'

def test_empty_code_cell():
cell = new_code_cell('hi')
nt.assert_equal(cell.cell_type, 'code')
nt.assert_equal(cell.source, u'hi')
assert cell.cell_type == 'code'
assert cell.source == u'hi'

def test_empty_display_data():
output = new_output('display_data')
nt.assert_equal(output.output_type, 'display_data')
assert output.output_type == 'display_data'

def test_empty_stream():
output = new_output('stream')
nt.assert_equal(output.output_type, 'stream')
nt.assert_equal(output.name, 'stdout')
nt.assert_equal(output.text, '')
assert output.output_type == 'stream'
assert output.name == 'stdout'
assert output.text == ''

def test_empty_execute_result():
output = new_output('execute_result', execution_count=1)
nt.assert_equal(output.output_type, 'execute_result')
assert output.output_type == 'execute_result'

mimebundle = {
'text/plain': "some text",
Expand All @@ -66,36 +64,36 @@ def test_empty_execute_result():
def test_display_data():
output = new_output('display_data', mimebundle)
for key, expected in mimebundle.items():
nt.assert_equal(output.data[key], expected)
assert output.data[key] == expected

def test_execute_result():
output = new_output('execute_result', mimebundle, execution_count=10)
nt.assert_equal(output.execution_count, 10)
assert output.execution_count == 10
for key, expected in mimebundle.items():
nt.assert_equal(output.data[key], expected)
assert output.data[key] == expected

def test_error():
o = new_output(output_type=u'error', ename=u'NameError',
evalue=u'Name not found', traceback=[u'frame 0', u'frame 1', u'frame 2']
)
nt.assert_equal(o.output_type, u'error')
nt.assert_equal(o.ename, u'NameError')
nt.assert_equal(o.evalue, u'Name not found')
nt.assert_equal(o.traceback, [u'frame 0', u'frame 1', u'frame 2'])
assert o.output_type == u'error'
assert o.ename == u'NameError'
assert o.evalue == u'Name not found'
assert o.traceback == [u'frame 0', u'frame 1', u'frame 2']

def test_code_cell_with_outputs():
cell = new_code_cell(execution_count=10, outputs=[
new_output('display_data', mimebundle),
new_output('stream', text='hello'),
new_output('execute_result', mimebundle, execution_count=10),
])
nt.assert_equal(cell.execution_count, 10)
nt.assert_equal(len(cell.outputs), 3)
assert cell.execution_count == 10
assert len(cell.outputs) == 3
er = cell.outputs[-1]
nt.assert_equal(er.execution_count, 10)
nt.assert_equal(er['output_type'], 'execute_result')
assert er.execution_count == 10
assert er['output_type'] == 'execute_result'

def test_stream():
output = new_output('stream', name='stderr', text='hello there')
nt.assert_equal(output.name, 'stderr')
nt.assert_equal(output.text, 'hello there')
assert output.name == 'stderr'
assert output.text == 'hello there'
26 changes: 13 additions & 13 deletions nbformat/v4/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io
import os

import nose.tools as nt
import pytest

from nbformat.validator import validate, ValidationError
from ..nbjson import reads
Expand All @@ -27,75 +27,75 @@ def test_invalid_code_cell():
cell = new_code_cell()

cell['source'] = 5
with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'code_cell')

cell = new_code_cell()
del cell['metadata']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'code_cell')

cell = new_code_cell()
del cell['source']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'code_cell')

cell = new_code_cell()
del cell['cell_type']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'code_cell')

def test_invalid_markdown_cell():
cell = new_markdown_cell()

cell['source'] = 5
with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'markdown_cell')

cell = new_markdown_cell()
del cell['metadata']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'markdown_cell')

cell = new_markdown_cell()
del cell['source']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'markdown_cell')

cell = new_markdown_cell()
del cell['cell_type']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'markdown_cell')

def test_invalid_raw_cell():
cell = new_raw_cell()

cell['source'] = 5
with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'raw_cell')

cell = new_raw_cell()
del cell['metadata']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'raw_cell')

cell = new_raw_cell()
del cell['source']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'raw_cell')

cell = new_raw_cell()
del cell['cell_type']

with nt.assert_raises(ValidationError):
with pytest.raises(ValidationError):
validate4(cell, 'raw_cell')

def test_sample_notebook():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
]

extras_require = setuptools_args['extras_require'] = {
'test': ['testpath'],
'test': ['testpath', 'pytest', 'pytest-cov'],
}

if 'setuptools' in sys.modules:
Expand Down

0 comments on commit f761e7e

Please sign in to comment.