[tox]
envlist = py37,pep8
minversion = 3.1.1
skipsdist = True

[testenv]
setenv = VIRTUAL_ENV={envdir}
         OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
         OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
         OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
         PYTHONWARNINGS=default::DeprecationWarning
passenv = TRACE_FAILONLY
usedevelop = True
install_command = pip install {opts} {packages}
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/victoria}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
whitelist_externals =
    sh
    find
commands =
  find . -type f -name "*.py[c|o]" -delete
  find -path "*/__pycache__*" -delete
  stestr run {posargs}
# there is also secret magic in ostestr which lets you run in a fail only
# mode. To do this define the TRACE_FAILONLY environmental variable.

[testenv:functional]
setenv =
  {[testenv]setenv}
  OS_TEST_PATH=./networking_sfc/tests/functional

[testenv:dsvm-functional]
setenv =
    {[testenv]setenv}
    OS_TEST_PATH=./networking_sfc/tests/functional
    OS_SUDO_TESTING=1
    OS_FAIL_ON_MISSING_DEPS=1
    OS_TEST_TIMEOUT=180
    OS_TESTR_CONCURRENCY=1
    OS_LOG_PATH={env:OS_LOG_PATH:/opt/stack/logs}
whitelist_externals =
  sh
  cp
  sudo
commands = stestr run {posargs}

[testenv:pep8]
commands =
  flake8
  pylint --rcfile=.pylintrc --output-format=colorized {posargs:networking_sfc}
  {toxinidir}/tools/check_unit_test_structure.sh
  neutron-db-manage --subproject networking-sfc --database-connection sqlite:// check_migration
  {[testenv:genconfig]commands}
  {[testenv:genpolicy]commands}
whitelist_externals = sh

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

[testenv:venv]
commands = {posargs}

[testenv:docs]
deps = -r{toxinidir}/doc/requirements.txt
commands = sphinx-build -W -b html -d doc/build/doctrees doc/source doc/build/html

[testenv:pdf-docs]
deps = {[testenv:docs]deps}
envdir = {toxworkdir}/docs
whitelist_externals =
  make
commands =
  sphinx-build -W -b latex doc/source doc/build/pdf
  make -C doc/build/pdf

[flake8]
# TODO(dougwig) -- uncomment this to test for remaining linkages
# N530 direct neutron imports not allowed
# W504 line break after binary operator
ignore = N530,W504
# From neutron-lib flake8
# H904: Delay string interpolations at logging calls
enable-extensions=H904
show-source = true
builtins = _
exclude = ./.*,build,dist
import-order-style = pep8

[hacking]
import_exceptions = networking_sfc._i18n
local-check-factory = neutron_lib.hacking.checks.factory

[testenv:api-ref]
whitelist_externals = rm
deps = {[testenv:docs]deps}
envdir = {toxworkdir}/docs
commands =
  rm -rf api-ref/build
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html

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

[testenv:releasenotes]
deps = {[testenv:docs]deps}
envdir = {toxworkdir}/docs
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html

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

[testenv:genpolicy]
commands = oslopolicy-sample-generator --config-file=etc/oslo-policy-generator/policy.conf

[testenv:dev]
# run locally (not in the gate) using editable mode
# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs
commands =
    pip install -q -e "git+https://opendev.org/openstack/neutron#egg=neutron"

[testenv:py-dev]
commands =
    {[testenv:dev]commands}
    {[testenv]commands}

[testenv:pep8-dev]
deps =
    {[testenv]deps}
commands =
    {[testenv:dev]commands}
    {[testenv:pep8]commands}

# This environment can be used to quickly validate that all needed system
# packages required to successfully execute test targets are installed
[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
