diff --git a/.travis.yml b/.travis.yml index d8bfb01..0814116 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,24 @@ language: python python: - - "2.6" - "2.7" - - "3.2" - "3.3" - "3.4" - "3.5" - - "3.6-dev" + - "3.6" + - "3.7-dev" - "pypy" + - "pypy3" install: - pip install coverage + - pip install --upgrade pytest pytest-benchmark script: - | if [[ $(bc <<< "$TRAVIS_PYTHON_VERSION >= 3.3") -eq 1 ]]; then - nosetests --with-doctest + py.test --doctest-modules multipledispatch else - nosetests --with-doctest -I '.*_3only.py$' + py.test --doctest-modules --ignore=multipledispatch/tests/test_dispatcher_3only.py multipledispatch fi after_success: diff --git a/multipledispatch/tests/test_benchmark.py b/multipledispatch/tests/test_benchmark.py new file mode 100644 index 0000000..3041ef0 --- /dev/null +++ b/multipledispatch/tests/test_benchmark.py @@ -0,0 +1,45 @@ +from multipledispatch import dispatch +import pytest + + +@dispatch(int) +def isint(x): + return True + + +@dispatch(object) +def isint(x): + return False + + +@dispatch(object, object) +def isint(x, y): + return False + + +@pytest.mark.parametrize("val", [1, 'a']) +def test_benchmark_call_single_dispatch(benchmark, val): + benchmark(isint, val) + + +@pytest.mark.parametrize("val", [(1, 4)]) +def test_benchmark_call_multiple_dispatch(benchmark, val): + benchmark(isint, *val) + + +def test_benchmark_add_and_use_instance(benchmark): + namespace = {} + + @benchmark + def inner(): + @dispatch(int, int, namespace=namespace) + def mul(x, y): + return x * y + + @dispatch(str, int, namespace=namespace) + def mul(x, y): + return x * y + + mul(4, 5) + mul('x', 5) + diff --git a/multipledispatch/tests/test_core.py b/multipledispatch/tests/test_core.py index 373ce99..d3f6eec 100644 --- a/multipledispatch/tests/test_core.py +++ b/multipledispatch/tests/test_core.py @@ -28,7 +28,7 @@ def f(x): assert raises(NotImplementedError, lambda: f('hello')) -def test_multipledispatch(): +def test_multipledispatch(benchmark): @dispatch(int, int) def f(x, y): return x + y