[tox]
envlist = pep8,py38,py39,py3-dj111
minversion = 3.1
skipsdist = True
# Automatic envs (pyXX) will only use the python version appropriate to that
# env and ignore basepython inherited from [testenv] if we set
# ignore_basepython_conflict.
ignore_basepython_conflict = True

[testenv]
basepython = python3
usedevelop = True
install_command = pip install {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
# Note the hash seed is set to 0 until gbpui can be tested with a
# random hash seed successfully.
         PYTHONHASHSEED=0
deps =
    -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga}
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/test-requirements.txt
commands = /bin/bash run_tests.sh -N --no-pep8 {posargs}

[testenv:pep8]
# NOTE: Due to doc dependencies, we don't share envdir with "venv".
# sphinx (precisely Pygments) needs to be installed to make doc8 work properly
deps =
  {[testenv]deps}
  -r{toxinidir}/doc/requirements.txt
setenv =
  {[testenv]setenv}
  DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings
commands =
  /bin/bash run_tests.sh -N --pep8

[testenv:venv]
commands = {posargs}

[testenv:cover]
envdir = {toxworkdir}/venv
commands =
  coverage erase
  coverage run {toxinidir}/manage.py test gbpui/horizon --settings=horizon.test.settings {posargs}
  coverage run -a {toxinidir}/manage.py test gbpui/openstack_dashboard --settings=openstack_dashboard.test.settings --exclude-tag integration {posargs}
  coverage xml
  coverage html

[testenv:jshint]
commands = nodeenv -p
           npm install jshint -g
           /bin/bash run_tests.sh -N --jshint

[testenv:docs]
# We need to install horizon dependecies to build module references
deps =
  -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/train}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/doc/requirements.txt
setenv = DJANGO_SETTINGS_MODULE=openstack_dashboard.test.settings
commands = python setup.py build_sphinx

[testenv:py3-dj21]
commands = pip install django>=2.1<2.2
           /bin/bash run_tests.sh -N --no-pep8 {posargs}

[testenv:py3-dj111]
commands = pip install django>=1.11,<2
           /bin/bash run_tests.sh -N --no-pep8 {posargs}

[testenv:py3integration]
envdir = {toxworkdir}/venv
# Run integration tests only
setenv =
  PYTHONHASHSEED=0
  INTEGRATION_TESTS=1
  SELENIUM_HEADLESS=1
commands =
    {envpython} {toxinidir}/manage.py test gbpui/openstack_dashboard --settings=openstack_dashboard.test.settings --verbosity 2 --tag integration {posargs}
    {envpython} {toxinidir}/manage.py test gbpui/horizon --settings=openstack_dashboard.test.settings --verbosity 2 --tag integration {posargs}

[flake8]
exclude = .venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject
# E731 do not assign a lambda expression, use a def
# E127 continuation line over-indented for visual indent
# E128 continuation line under-indented for visual indent
# F405 TEMPLATES may be undefined, or defined from star imports
# (because it is not easy to avoid this in openstack_dashboard.test.settings)
# H307  like imports should be grouped together
# H405  multi line docstring summary not separated with an empty line
# H803 git commit title should not end with period (disabled on purpose, see bug #1236621)
# H904  Wrap long lines in parentheses instead of a backslash
# W504 line break after binary operator
# (W503 and W504 are incompatible and we need to choose one of them.
#  Existing codes follows W503, so we disable W504.)
ignore = E127,E128,E731,F405,H307,H405,H803,H904,W504

[hacking]
import_exceptions = collections.defaultdict,
                    django.conf.settings,
                    django.conf.urls.patterns,
                    django.conf.urls.url,
                    django.core.urlresolvers.reverse,
                    django.core.urlresolvers.reverse_lazy,
                    django.template.loader.render_to_string,
                    django.test.utils.override_settings,
                    django.utils.datastructures.SortedDict,
                    django.utils.encoding.force_text,
                    django.utils.html.conditional_escape,
                    django.utils.html.escape,
                    django.utils.http.urlencode,
                    django.utils.safestring.mark_safe,
                    django.utils.translation.npgettext_lazy,
                    django.utils.translation.pgettext_lazy,
                    django.utils.translation.ugettext_lazy,
                    django.utils.translation.ungettext_lazy,
                    operator.attrgetter,
                    StringIO.StringIO
