[tox]
envlist = docs,pep8,pylint,yamllint,bashate,py27,perm,cover

[testenv]
usedevelop = True
deps =
  -c{toxinidir}/upper-constraints.txt
  -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt?h=stable/queens}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
install_command = pip install {opts} {packages}
commands = nosetests --with-xunit \
  --with-coverage \
  --cover-tests \
  --cover-package=functest \
  --cover-xml \
  --cover-html \
  --with-html-output \
  functest/tests/unit

[testenv:docs]
basepython = python2.7
commands =
  doc8 \
    --ignore-path api/build \
    --ignore-path docs/build \
    --ignore-path docs/_build \
    api \
    docs
  sphinx-build -W -b html api/ api/build
  sphinx-build -W -n -b html docs docs/build/html
  sphinx-build -W -n -b linkcheck docs docs/_build/linkcheck
  sphinx-build -W -n -b html -c docs/lfreleng docs docs/_build/html

[testenv:pep8]
basepython = python2.7
commands = flake8

[testenv:pylint]
basepython = python2.7
whitelist_externals = bash
modules =
  functest.ci
  functest.opnfv_tests.openstack.cinder
  functest.opnfv_tests.openstack.rally
  functest.opnfv_tests.openstack.refstack
  functest.opnfv_tests.openstack.snaps
  functest.opnfv_tests.openstack.tempest
  functest.opnfv_tests.openstack.vmtp
  functest.opnfv_tests.openstack.vping
  functest.opnfv_tests.sdn.odl
  functest.opnfv_tests.vnf.router
  functest.tests.unit.ci
  functest.tests.unit.odl
  functest.tests.unit.openstack.rally
  functest.tests.unit.openstack.snaps
  functest.tests.unit.openstack.tempest
  functest.tests.unit.openstack.vmtp
  functest.tests.unit.openstack.vping
  functest.tests.unit.vnf.router
  functest.tests.unit.utils
  functest.utils.config
  functest.utils.constants
  functest.utils.env
  functest.utils.functest_utils
commands =
  bash -c "\
    pylint -f parseable \
        --ignore-imports=y \
        --disable=locally-disabled functest | tee pylint.out"
  pylint --reports=n --errors-only functest
  pylint --disable=locally-disabled \
    --disable=duplicate-code \
    --ignore-imports=y --reports=n {[testenv:pylint]modules}

[testenv:yamllint]
basepython = python2.7
files =
  .travis.yml
  ci
  docker
  functest/ci
  functest/opnfv_tests/openstack/rally/rally_jobs.yaml
  functest/opnfv_tests/openstack/tempest/custom_tests/blacklist.yaml
  functest/opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml
  functest/opnfv_tests/vnf
commands =
  yamllint -s {[testenv:yamllint]files}

[testenv:py36]
dirs =
  functest/tests/unit/ci
  functest/tests/unit/odl
  functest/tests/unit/openstack
  functest/tests/unit/vnf/epc
  functest/tests/unit/utils
commands = nosetests {[testenv:py36]dirs}

[testenv:bashate]
basepython = python2.7
files =
  functest/opnfv_tests/openstack/cinder/write_data.sh
  functest/opnfv_tests/openstack/cinder/read_data.sh
  functest/ci/add_proxy.sh
  functest/ci/convert_images.sh
  functest/ci/download_images.sh
  build.sh
commands = bashate {[testenv:bashate]files}

[testenv:cover]
basepython = python2.7
dirs =
  functest/tests/unit/ci
  functest/tests/unit/odl
  functest/tests/unit/openstack/vping
  functest/tests/unit/openstack/cinder
commands = nosetests --with-coverage --cover-tests \
  --cover-package functest.ci.check_deployment \
  --cover-package functest.opnfv_tests.sdn.odl \
  --cover-package functest.opnfv_tests.openstack.vping.vping_ssh \
  --cover-package functest.opnfv_tests.openstack.cinder.cinder_test \
  --cover-package functest.tests.unit \
  --cover-min-percentage 100 {[testenv:cover]dirs}

[testenv:perm]
basepython = python2.7
whitelist_externals = bash
path=. -not -path './.tox/*' -not -path './.git/*' -not -path './docs/com/pres/reveal.js/*'
commands =
  bash -c "\
    find {[testenv:perm]path} \( -type f -not -perm 644 -o -type d -not -perm 755 \) \
    -exec ls -l \{\} + | grep '.' && exit 1 || exit 0"
  bash -c "\
    find {[testenv:perm]path} -exec file \{\} + | grep CRLF && exit 1 || exit 0"