[tox]
envlist = black, flake8, pylint, py{26,27,36,37}, ensure_non_running_provider
skipsdist = true
skip_missing_interpreters = True

[testenv]
basepython = python3
deps =
    py{26,27,36,37,38}: pytest-cov
    py{27,36,37,38}: pytest>=3.5.1
    py{26,27}: mock
    py26: pytest
    molecule_{lint,syntax,test}: docker
    molecule_{lint,syntax,test}: jmespath
    molecule_{lint,syntax,test}: molecule
    # The selinux pypi shim does not work with Ubuntu (as used by Travis), yet.
    # Therefore use a fork with Ubuntu support. This can be changed once the
    # update is available on PyPi.
    # molecule_{lint,syntax,test}: selinux
    molecule_{lint,syntax,test}: git+https://github.com/tyll/selinux-pypi-shim@fulllocation

[base]
passenv = *
setenv =
    PYTHONPATH = {toxinidir}/library:{toxinidir}/module_utils
    LC_ALL = C
changedir = {toxinidir}/tests
covtarget = {toxinidir}/library --cov {toxinidir}/module_utils
pytesttarget = .

[testenv:black]
deps = black

commands = black --check --diff --include "^[^.].*\.py$" .

[testenv:py26]
install_command = pip install {opts} {packages}
list_dependencies_command = pip freeze
basepython = python2.6
passenv = {[base]passenv}
setenv =
    {[base]setenv}
changedir = {[base]changedir}
commands =
    pytest \
        --durations=5 \
        --cov={[base]covtarget} \
        --cov-report=html:htmlcov-py26 --cov-report=term \
        {posargs} \
        {[base]pytesttarget}

[testenv:py27]
basepython = python2.7
passenv = {[base]passenv}
setenv =
    {[base]setenv}
changedir = {[base]changedir}
commands =
    pytest \
        --durations=5 \
        --cov={[base]covtarget} \
        --cov-report=html:htmlcov-py27 --cov-report=term \
        {posargs} \
        {[base]pytesttarget}

[testenv:py36]
basepython = python3.6
passenv = {[base]passenv}
setenv =
    {[base]setenv}
changedir = {[base]changedir}
commands =
    pytest \
        --durations=5 \
        --cov={[base]covtarget} \
        --cov-report=html:htmlcov-py36 --cov-report=term \
        {posargs} \
        {[base]pytesttarget}

[testenv:py37]
basepython = python3.7
passenv = {[base]passenv}
setenv =
    {[base]setenv}
changedir = {[base]changedir}
commands =
    pytest \
        --durations=5 \
        --cov={[base]covtarget} \
        --cov-report=html:htmlcov-py37 --cov-report=term \
        {posargs} \
        {[base]pytesttarget}

[testenv:py38]
passenv = {[base]passenv}
setenv =
    {[base]setenv}
changedir = {[base]changedir}
basepython = python3.8
commands =
    pytest \
        --durations=5 \
        --cov={[base]covtarget} \
        --cov-report=html:htmlcov-py38 --cov-report=term \
        {posargs} \
        {[base]pytesttarget}

[testenv:pylint]
basepython = python2.7
setenv =
    {[base]setenv}
deps =
    pylint>=1.8.4
    ansible
commands =
    pylint \
        --errors-only \
        {posargs} \
        library/network_connections.py \
        module_utils/network_lsr \
        tests/unit/test_network_connections.py

[testenv:flake8]
basepython = python2.7
deps =
    flake8>=3.5
whitelist_externals = flake8
commands=
    flake8 --statistics {posargs} \
        .

[testenv:coveralls]
basepython = python2.7
passenv = TRAVIS TRAVIS_*
deps =
    coveralls
changedir = {[base]changedir}
commands =
    coveralls

[testenv:ensure_non_running_provider]
deps =
    PyYAML
changedir = {toxinidir}/tests
commands = {toxinidir}/tests/ensure_non_running_provider.py

[testenv:molecule_lint]
commands_pre =
    molecule --version
    ansible --version
commands = molecule {posargs} lint

[testenv:molecule_syntax]
commands = molecule {posargs} syntax

[testenv:molecule_test]
commands = molecule {posargs} test

[pytest]
addopts = -rxs

[flake8]
show_source = True
max-line-length = 88
ignore = E402,W503

[pylint]
max-line-length = 88
disable = wrong-import-position

[pycodestyle]
max-line-length = 88

[travis]
python =
  2.6: py26
  2.7: py27,coveralls,flake8,pylint
  3.5: molecule_lint,molecule_syntax,molecule_test
  3.6: py36,black,ensure_non_running_provider
  3.7: py37
  3.8: py38
