[tox]
envlist = py27,py37,pep8,cover
minversion = 2.7
skipsdist = True

[testenv]
usedevelop = True
setenv = VIRTUAL_ENV={envdir}
         OS_TEST_PATH=monasca_events_api/tests/unit
passenv = *_proxy
          *_PROXY
whitelist_externals = bash
                      find
                      rm
install_command = pip install {opts} {packages}
deps =
  -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
 -r{toxinidir}/test-requirements.txt
 -r{toxinidir}/requirements.txt
commands =
  find ./ -type f -name '*.pyc' -delete
  rm -Rf .testrepository/times.dbm

[testenv:py27]
description = Runs unit test using Python2.7
basepython = python2.7
commands =
  {[testenv]commands}
  stestr run {posargs}

[testenv:py36]
description = Runs unit test using Python3.6
basepython = python3.6
commands =
  {[testenv]commands}
  stestr run {posargs}

[testenv:cover]
basepython = python3
description = Calculates code coverage
setenv =
    PYTHON=coverage run --source monasca_events_api --parallel-mode
commands =
    stestr run {posargs}
    coverage combine
    coverage html -d cover
    coverage xml -o cover/coverage.xml

[testenv:debug]
basepython = python3
description = Allows to run unit-test with debug mode enabled
commands =
  {[testenv]commands}
  oslo_debug_helper -t {env:OS_TEST_PATH} {posargs}

[testenv:bashate]
basepython = python3
description = Validates (pep8-like) devstack plugins
skip_install = True
usedevelop = False
commands = bash {toxinidir}/tools/bashate.sh

[testenv:bandit]
basepython = python3
skip_install = True
usedevelop = False
commands = bandit -r monasca_events_api -n5 -x monasca_events_api/tests

[testenv:flake8]
basepython = python3
skip_install = True
usedevelop = False
commands =
  flake8 monasca_events_api

[testenv:pep8]
basepython = python3
description = Runs set of linters against codebase (flake8, bandit, bashate, checkniceness)
commands =
  {[testenv:flake8]commands}
  {[testenv:bandit]commands}
  {[testenv:bashate]commands}
  {[testenv:checkniceness]commands}

[testenv:docs]
basepython = python3
description = Builds api-ref, releasenotes and devdocs
commands =
  {[testenv:devdocs]commands}
  {[testenv:api-ref]commands}
  {[testenv:releasenotes]commands}

[testenv:api-ref]
basepython = python3
description = Called from CI scripts to test and publish the API Ref
commands =
  rm -rf api-ref/build
  {[testenv:checkjson]commands}
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html

[testenv:releasenotes]
basepython = python3
description = Called from CI script to test and publish the Release Notes
commands =
  rm -rf releasenotes/build
  sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html

[testenv:devdocs]
basepython = python3
description = Builds developer documentation
commands =
  {[testenv]commands}
  rm -rf doc/build
  rm -rf doc/source/contributor/api
  {[testenv:checkjson]commands}
  python setup.py build_sphinx

[testenv:checkniceness]
basepython = python3
description = Validates (pep-like) documentation
skip_install = True
usedevelop = False
commands =
  doc8 --file-encoding utf-8 {toxinidir}/doc
  doc8 --file-encoding utf-8 {toxinidir}/api-ref
  doc8 --file-encoding utf-8 {toxinidir}/releasenotes

[testenv:checkjson]
basepython = python3
description = Validates all json samples inside doc folder
deps =
whitelist_externals =
    bash
    python
commands =
  bash -c "! find doc/ -type f -name *.json | xargs grep -U -n $'\r'"
  bash -c '! find doc/ -type f -name *.json | xargs -t -n1 python -m json.tool 2>&1 > /dev/null | grep -B1 -v ^python'

[testenv:genconfig]
basepython = python3
description = Generates sample documentation file for monasca-events-api
commands = oslo-config-generator --config-file=config-generator/config.conf

[testenv:genpolicy]
basepython = python3
description = Generates sample policy.yaml file for monasca-events-api
commands = oslopolicy-sample-generator --config-file=config-generator/policy.conf

[testenv:venv]
basepython = python3
commands = {posargs}

[flake8]
exclude = .git,.gitignore,.tox,dist,doc,api-ref,releasenotes,*.egg,build,
          __pycache__
show-source = True
enable-extensions = H203,H106
ignore = D100,D104
import-order-style = pep8

[testenv:lower-constraints]
basepython = python3
deps =
  -c{toxinidir}/lower-constraints.txt
  -r{toxinidir}/test-requirements.txt
  -r{toxinidir}/requirements.txt

[hacking]
