[tox]
minversion = 1.6
skipsdist = True
envlist = py27,py34,functional,py34-functional,pep8

[testenv]
deps = -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
install_command = pip install -U {opts} {packages}
usedevelop = True
setenv = VIRTUAL_ENV={envdir}
         OS_TEST_PATH=ceilometer/tests/unit
passenv = OS_TEST_TIMEOUT OS_STDOUT_CAPTURE OS_STDERR_CAPTURE OS_LOG_CAPTURE
commands =
   {toxinidir}/tools/pretty_tox.sh "{posargs}"
   oslo-config-generator --config-file=etc/ceilometer/ceilometer-config-generator.conf
whitelist_externals = bash

# TODO(ityaptin): With separation tests to unit and functional folders we need
# set environment variable OS_TEST_PATH=./ceilometer/tests/functional
# in "py-<backend>" jobs

[testenv:py-mongodb]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
   bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"

[testenv:py-mysql]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
   bash -x {toxinidir}/setup-test-env-mysql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"

[testenv:py-pgsql]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
   bash -x {toxinidir}/setup-test-env-postgresql.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"

# Functional tests for elastic search
[testenv:py-elastic]
setenv = OS_TEST_PATH=ceilometer/tests/functional/
commands =
   bash -x {toxinidir}/setup-test-env-es.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"

[testenv:functional]
setenv = VIRTUAL_ENV={envdir}
         OS_TEST_PATH=ceilometer/tests/functional/
passenv = CEILOMETER_*
commands =
   bash -x {toxinidir}/run-functional-tests.sh "{posargs}"

[testenv:py34-functional]
setenv = VIRTUAL_ENV={envdir}
         OS_TEST_PATH=ceilometer/tests/functional/
basepython = python3.4
passenv = CEILOMETER_*
commands =
   bash -x {toxinidir}/run-functional-tests.sh "{posargs}"

[testenv:integration]
setenv = VIRTUAL_ENV={envdir}
         OS_TEST_PATH=./ceilometer/tests/integration
         OS_TEST_TIMEOUT=2400
         GABBI_LIVE_FAIL_IF_NO_TEST=1
passenv = {[testenv]passenv} HEAT_* CEILOMETER_* GNOCCHI_* AODH_* GLANCE_* NOVA_* ADMIN_*
# FIXME(sileht): run gabbi-run to failfast in case of error because testr
# doesn't support --failfast, but we loose the testr report.
commands =
   bash -c 'cd ceilometer/tests/integration/gabbi/gabbits-live && gabbi-run -x < autoscaling.yaml'
#   bash -x {toxinidir}/tools/pretty_tox.sh "{posargs}"

# NOTE(chdent): The gabbi tests are also run under the other functional
# tox targets. This target simply provides a target to directly run just
# gabbi tests without needing to do discovery across the entire body of
# tests.
[testenv:gabbi]
setenv = OS_TEST_PATH=ceilometer/tests/functional/gabbi
passenv = CEILOMETER_*
commands =
    bash -x {toxinidir}/setup-test-env-mongodb.sh {toxinidir}/tools/pretty_tox.sh "{posargs}"

[testenv:cover]
setenv = OS_TEST_PATH=ceilometer/tests
commands =
   python setup.py testr --slowest --coverage --testr-args="{posargs}"

[testenv:pep8]
commands =
    flake8
    # Check that .po and .pot files are valid:
    bash -c "find ceilometer -type f -regex '.*\.pot?' -print0|xargs -0 -n 1 msgfmt --check-format -o /dev/null"

[testenv:releasenotes]
commands = sphinx-build -a -E -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html

[testenv:genconfig]
commands = oslo-config-generator --config-file=etc/ceilometer/ceilometer-config-generator.conf

[testenv:docs]
commands = python setup.py build_sphinx
setenv = PYTHONHASHSEED=0

[testenv:pylint]
commands = bash tools/lintstack.sh

[testenv:venv]
commands = {posargs}
setenv = PYTHONHASHSEED=0

[testenv:debug]
commands = bash -x oslo_debug_helper {posargs}

[testenv:debug-mongodb]
setenv = OS_TEST_PATH=ceilometer/tests/functional
commands = bash -x {toxinidir}/setup-test-env-mongodb.sh oslo_debug_helper {posargs}

[testenv:debug-mysql]
setenv = OS_TEST_PATH=ceilometer/tests/functional
commands = bash -x {toxinidir}/setup-test-env-mysql.sh oslo_debug_helper {posargs}

[testenv:debug-pgsql]
setenv = OS_TEST_PATH=ceilometer/tests/functional
commands = bash -x {toxinidir}/setup-test-env-pgsql.sh oslo_debug_helper {posargs}

[testenv:debug-elastic]
setenv = OS_TEST_PATH=ceilometer/tests/functional
commands = bash -x {toxinidir}/setup-test-env-es.sh oslo_debug_helper {posargs}

[flake8]
ignore =
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
show-source = True

[hacking]
import_exceptions =
    ceilometer.i18n
