[tox]
envlist = py27,py35,pep8
minversion = 2.1
skipsdist = True

[testenv]
setenv =
    VIRTUAL_ENV={envdir}
    DISCOVER_DIRECTORY=tests
passenv = http_proxy
          HTTP_PROXY
          https_proxy
          HTTPS_PROXY
          no_proxy
          NO_PROXY
usedevelop = True
whitelist_externals = bash
                      find
                      rm
install_command = pip install {opts} {packages}
deps =
  -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/rocky}
  .[influxdb,cassandra,elasticsearch]
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
commands =
  find {toxinidir} -type f -name "*.py[c|o]" -delete
  rm -Rf .testrepository/times.dbm
  stestr run {posargs}

[testenv:cover]
setenv =
    PYTHON=coverage run --source monasca_persister --parallel-mode
commands =
    stestr run '{posargs}'
    coverage combine
    coverage html -d cover
    coverage xml -o cover/coverage.xml

[testenv:debug]
commands = oslo_debug_helper -t monasca_persister/tests {posargs}

[testenv:pep8]
deps =
  {[testenv]deps}
commands =
  {[testenv:flake8]commands}
  {[bandit]commands}

[testenv:genconfig]
description = Generates sample configuration file for monasca-persister
whitelist_externals = bash
commands =
  oslo-config-generator --config-file=config-generator/persister.conf

[testenv:venv]
commands = {posargs}

[testenv:bindep]
# Do not install any requirements. We want this to be fast and work even if
# system dependencies are missing, since it's used to tell you what system
# dependencies are missing! This also means that bindep must be installed
# separately, outside of the requirements files.
deps = bindep
commands = bindep test

[testenv:flake8]
commands =
    flake8 monasca_persister

[flake8]
max-line-length = 100
# TODO: ignored checks should be enabled in the future
# H405  multi line docstring summary not separated with an empty line
ignore = F821,H405,H306,E302
exclude=.venv,.git,.tox,dist,*egg,build

[bandit]
commands =
# B303  cassandra metrics repository uses SHA1 for metric_id
  bandit -r monasca_persister -n5 -s B303 -x monasca_persister/tests

[hacking]
local-check-factory = monasca_persister.hacking.checks.factory

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