# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# tests suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = yaml, flake8, py36, py37, py38, pypy3, mypy, docs, manifest, coverage-report
toxworkdir=/tmp/.tox.yacfg/

[pytest]
addopts = -ra -vv --cov=yacfg --cov=yacfg_batch --cov-report=xml
testpaths = tests

[flake8]
max-line-length = 160
exclude = .*, tests/*, docs/*, venv/*
max-complexity = 10

[gh-actions]
python =
    3.6: py36
    3.7: py37, docs
    3.8: py38, flake8, yaml, mypy, manifest
    3.9: py39
    pypy3: pypy3

[testenv]
changedir = tests
extras = testing
setenv =
    PYTHONUNBUFFERED=yes
    COVERAGE_FILE={envtmpdir}/.coverage
whitelist_externals =
    mv
    mkdir

description = Run tests and measure coverage
deps =
    pytest
    pytest-cov
    mock
    pyyaml
    jinja2
commands =
    pytest --basetemp="{envtmpdir}" {posargs}
    mkdir -p {toxinidir}/.coverage-reports
    mv {envtmpdir}/.coverage {toxinidir}/.coverage-reports/.coverage.{env:COVERAGE_PREFIX:}{envname}

[testenv:flake8]
changedir = src/
deps = flake8
commands = flake8 --exit-zero

[testenv:yaml]
changedir = src/
deps = yamllint
commands = yamllint .

[testenv:mypy]
changedir = .
description = Check types
deps = mypy
basepython = python3.8
commands = mypy src --ignore-missing-imports

[testenv:manifest]
description = Ensure MANIFEST.in is up to date.
changedir = .
basepython = python3.8
deps = check-manifest
commands = check-manifest {posargs}

[testenv:pre-commit]
description = Run all pre-commit hooks
changedir = .
basepython = python3.8
skip_install = true
deps = pre-commit
commands = pre-commit {posargs:run --all-files}

[testenv:profile-test]
changedir = .
allowlist_externals = bash
deps = bash
commands = bash profile_test.sh

[testenv:docs]
description = Build docs
changedir = .
basepython = python3.7
extras = docs
deps = jupyter-book
commands = jupyter-book build ./docs

[testenv:coverage-report]
description = Report coverage over all test runs.
changedir = .
deps = coverage
setenv =
    COVERAGE_FILE = {toxinidir}/.coverage-reports/.coverage
skip_install = true
commands =
    coverage combine {toxinidir}/.coverage-reports/
    coverage html --directory={toxinidir}/.coverage-reports/
    coverage report --show-missing
