# Copyright 2022 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, unit

[vars]
src_path = {toxinidir}/src/
tst_path = {toxinidir}/tests/
;lib_path = {toxinidir}/lib/charms/
all_path = {[vars]src_path} {[vars]tst_path}

[testenv]
basepython = python3
setenv =
  PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path}
  PYTHONBREAKPOINT=ipdb.set_trace
passenv =
  PYTHONPATH
  HOME
  PATH
  CHARM_BUILD_DIR
  MODEL_SETTINGS
  HTTP_PROXY
  HTTPS_PROXY
  NO_PROXY

[testenv:fmt]
description = Apply coding style standards to code
deps =
    black
    isort
commands =
    isort {[vars]all_path}
    black {[vars]all_path}

[testenv:lint]
description = Check code against coding style standards
deps =
    black
    flake8>= 4.0.0, < 5.0.0
    flake8-docstrings
    flake8-copyright
    flake8-builtins
    # prospector[with_everything]
    pylint
    pyproject-flake8
    pep8-naming
    isort
    codespell
    yamllint
    -r{toxinidir}/requirements.txt
commands =
    codespell {toxinidir}/*.yaml {toxinidir}/*.ini {toxinidir}/*.md \
      {toxinidir}/*.toml {toxinidir}/*.txt {toxinidir}/.github
    # prospector -A -F -T
    pylint -E {[vars]src_path}
    yamllint -d '\{extends: default, ignore: "build\n.tox" \}' .
    # pflake8 wrapper supports config from pyproject.toml
    pflake8 {[vars]all_path}
    isort --check-only --diff {[vars]all_path}
    black --check --diff {[vars]all_path}

[testenv:unit]
description = Run unit tests
deps =
    pytest
    pytest-mock
    pytest-cov
    coverage[toml]
    -r{toxinidir}/requirements.txt
commands =
    pytest --ignore={[vars]tst_path}integration --cov={[vars]src_path} --cov-report=xml
    coverage report

[testenv:security]
description = Run security tests
deps =
    bandit
    safety
commands =
    bandit -r {[vars]src_path}
    - safety check

[testenv:integration]
description = Run integration tests
deps =
    pytest
    pytest-operator
commands =
    pytest -v --tb native --ignore={[vars]tst_path}unit --log-cli-level=INFO -s {posargs}
