Skip to content
Merged
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
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
45 changes: 45 additions & 0 deletions multipledispatch/tests/test_benchmark.py
Original file line number Diff line number Diff line change
@@ -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)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the parametrized over a single call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually two arguments here. 1 and 'a'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly so that if we add more complex examples we can see which kinds of types are slower for tests. You can only use a benchmark once per test for some reason

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so it is because you plan on adding more cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah a large part of the reason I want to do this is for the fancier pytypes based checks in #69 where can dispatch on typed containers. That will potentially be slow.

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)

2 changes: 1 addition & 1 deletion multipledispatch/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down