diff --git a/.travis.yml b/.travis.yml index 61a58ca1..731343e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,36 @@ sudo: false language: python python: - - '2.6' - '2.7' - '3.3' - '3.4' - '3.5' - - '3.6-dev' + - '3.6' - pypy - nightly + # command to install dependencies install: "pip install -U tox" -# # command to run tests + +# command to run tests env: matrix: - TOXENV=py-pytest28 - TOXENV=py-pytest29 - TOXENV=py-pytest30 + matrix: include: - python: '2.7' env: TOXENV=check - - python: '3.5' + - python: '3.6' env: TOXENV=check + - python: '2.7' + env: TOXENV=benchmark + - python: '3.6' + env: TOXENV=benchmark + script: - tox --recreate -e $TOXENV diff --git a/testing/benchmark.py b/testing/benchmark.py new file mode 100644 index 00000000..e5888a5f --- /dev/null +++ b/testing/benchmark.py @@ -0,0 +1,50 @@ +""" +Benchmarking and performance tests. +""" +import pytest +from pluggy import _MultiCall, HookImpl, HookspecMarker, HookimplMarker + +hookspec = HookspecMarker("example") +hookimpl = HookimplMarker("example") + + +def MC(methods, kwargs, firstresult=False): + hookfuncs = [] + for method in methods: + f = HookImpl(None, "", method, method.example_impl) + hookfuncs.append(f) + return _MultiCall(hookfuncs, kwargs, {"firstresult": firstresult}) + + +@hookimpl +def hook(arg1, arg2, arg3): + return arg1, arg2, arg3 + + +@hookimpl(hookwrapper=True) +def wrapper(arg1, arg2, arg3): + yield + + +@pytest.fixture( + params=[0, 1, 10, 100], + ids="hooks={}".format, +) +def hooks(request): + return [hook for i in range(request.param)] + + +@pytest.fixture( + params=[0, 1, 10, 100], + ids="wrappers={}".format, +) +def wrappers(request): + return [wrapper for i in range(request.param)] + + +def inner_exec(methods): + return MC(methods, {'arg1': 1, 'arg2': 2, 'arg3': 3}).execute() + + +def test_hook_and_wrappers_speed(benchmark, hooks, wrappers): + benchmark(inner_exec, hooks + wrappers) diff --git a/tox.ini b/tox.ini index 9c027745..bf01970a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,37 +1,41 @@ [tox] -envlist=check,py{26,27,34,35,py}-pytest{28,29,30} +envlist=check,py{26,27,34,35,36,py}-pytest{28,29,30} [testenv] -commands= py.test {posargs:testing/} +commands=py.test {posargs:testing/} deps= pytest28: pytest~=2.8.0 pytest29: pytest~=2.9.0 pytest30: pytest~=3.0.0 +[testenv:benchmark] +commands=py.test {posargs:testing/benchmark.py} +deps= + pytest + pytest-benchmark [testenv:check] deps = flake8 - restructuredtext_lint -commands = + restructuredtext_lint +commands = flake8 pluggy.py setup.py testing rst-lint CHANGELOG.rst README.rst - [testenv:docs] deps = sphinx pygments - commands = sphinx-build \ -b html \ {toxinidir}/docs {toxinidir}/build/html-docs + [pytest] minversion=2.0 #--pyargs --doctest-modules --ignore=.tox -addopts= -rxsX -norecursedirs = .tox ja .hg .env* +addopts=-rxsX +norecursedirs=.tox ja .hg .env* [flake8] -max-line-length = 99 \ No newline at end of file +max-line-length=99