Skip to content

Commit 5a77a73

Browse files
mariusvniekerkmrocklin
authored andcommitted
Switch testing to pytest add benchmark test (#70)
* Switch testing to pytest, Use pytest-benchmark so that regressions can be tracked in future. * travis ensure up to date py.test * Move benchmarks to their own test file * pytest doesn't like very old versions of python
1 parent 4dd36b1 commit 5a77a73

3 files changed

Lines changed: 52 additions & 6 deletions

File tree

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
language: python
22
python:
3-
- "2.6"
43
- "2.7"
5-
- "3.2"
64
- "3.3"
75
- "3.4"
86
- "3.5"
9-
- "3.6-dev"
7+
- "3.6"
8+
- "3.7-dev"
109
- "pypy"
10+
- "pypy3"
1111

1212
install:
1313
- pip install coverage
14+
- pip install --upgrade pytest pytest-benchmark
1415

1516
script:
1617
- |
1718
if [[ $(bc <<< "$TRAVIS_PYTHON_VERSION >= 3.3") -eq 1 ]]; then
18-
nosetests --with-doctest
19+
py.test --doctest-modules multipledispatch
1920
else
20-
nosetests --with-doctest -I '.*_3only.py$'
21+
py.test --doctest-modules --ignore=multipledispatch/tests/test_dispatcher_3only.py multipledispatch
2122
fi
2223
2324
after_success:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from multipledispatch import dispatch
2+
import pytest
3+
4+
5+
@dispatch(int)
6+
def isint(x):
7+
return True
8+
9+
10+
@dispatch(object)
11+
def isint(x):
12+
return False
13+
14+
15+
@dispatch(object, object)
16+
def isint(x, y):
17+
return False
18+
19+
20+
@pytest.mark.parametrize("val", [1, 'a'])
21+
def test_benchmark_call_single_dispatch(benchmark, val):
22+
benchmark(isint, val)
23+
24+
25+
@pytest.mark.parametrize("val", [(1, 4)])
26+
def test_benchmark_call_multiple_dispatch(benchmark, val):
27+
benchmark(isint, *val)
28+
29+
30+
def test_benchmark_add_and_use_instance(benchmark):
31+
namespace = {}
32+
33+
@benchmark
34+
def inner():
35+
@dispatch(int, int, namespace=namespace)
36+
def mul(x, y):
37+
return x * y
38+
39+
@dispatch(str, int, namespace=namespace)
40+
def mul(x, y):
41+
return x * y
42+
43+
mul(4, 5)
44+
mul('x', 5)
45+

multipledispatch/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def f(x):
2828
assert raises(NotImplementedError, lambda: f('hello'))
2929

3030

31-
def test_multipledispatch():
31+
def test_multipledispatch(benchmark):
3232
@dispatch(int, int)
3333
def f(x, y):
3434
return x + y

0 commit comments

Comments
 (0)