# Scapy tox configuration file
# Copyright (C) 2018 Guillaume Valadon <guillaume@valadon.net>


[tox]
envlist = py{27,34,35,36,37,py,py3}-{linux,osx}_{non_root,root}, py{27,36}-windows-linux_garbage
skip_missing_interpreters = true
minversion = 2.9


[testenv:py27-pcapdnet_root]
description = "Scapy unit tests - pcap & dnet"
whitelist_externals = {[testenv]whitelist_externals}
passenv = SCAPY_USE_PCAPDNET
deps = mock
       cryptography
       coverage
       # Currently pcap & dnet are tested together. As pydumbnet does not
       # support Python3 yet, both are currently disabled.
       pcapy>=0.11.3
       pydumbnet
commands =
  sudo -E {envpython} -m coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c ./test/configs/osx.utsc -T test/bpf.uts -K manufdb -K tshark -K random_weird_py3 -K osx {posargs}


[testenv:linux_garbage]
description = "Scapy unit tests - garbage check"
commands = sudo -E {envpython} -Werror -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -K random_weird_py3 {posargs}
deps = {[testenv]deps}
passenv = {[testenv]passenv}
whitelist_externals = {[testenv]whitelist_externals}


[testenv:py36-isotp_kernel_module]
description = "Scapy unit tests - ISOTP Linux kernel module"
whitelist_externals = sudo
                      git
                      bash
                      lsmod
                      modprobe

passenv = PATH PWD PROGRAMFILES WINDIR SYSTEMROOT
deps = mock
       cryptography
       coverage
       python-can

commands =
  sudo -E modprobe can
  git clone --depth=1 https://github.com/linux-can/can-utils.git /tmp/can-utils
  bash -c "cd /tmp/can-utils; autogen.sh; ./configure; make; sudo make install"
  git clone --depth=1 https://github.com/hartkopp/can-isotp.git /tmp/can-isotp
  bash -c "cd /tmp/can-isotp; make; sudo make modules_install; sudo modprobe can_isotp || sudo insmod ./net/can/can-isotp.ko" 
  bash -c "rm -rf /tmp/can-utils /tmp/can-isotp"
  lsmod
  sudo -E {envpython} -m coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -K random_weird_py3 {posargs}


[testenv]
description = "Scapy unit tests"
whitelist_externals = sudo
passenv = PATH PWD PROGRAMFILES WINDIR SYSTEMROOT
deps = mock
       cryptography
       coverage
       python-can


platform =
  linux_non_root,linux_root: linux
  osx_non_root,osx_root: darwin
  windows: win32

commands =
  linux_non_root: coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -K random_weird_py3 -K netaccess -K needs_root {posargs}
  linux_root: sudo -E {envpython} -m coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c ./test/configs/linux.utsc -K random_weird_py3 {posargs}
  osx_non_root: coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c test/configs/osx.utsc -K manufdb -K tshark -K random_weird_py3 -K netaccess -K needs_root {posargs}
  osx_root: sudo -E {envpython} -m coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c test/configs/osx.utsc -K manufdb -K tshark -K random_weird_py3 {posargs}
  windows: {envpython} -m coverage run --rcfile=.coveragerc.tox -a -m scapy.tools.UTscapy -c test/configs/windows.utsc -K random_weird_py3 {posargs}
  coverage combine


[testenv:codecov]
description = "Upload coverage results to codecov"
passenv = TOXENV CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_*
deps = codecov
commands = codecov -e TOXENV

[testenv:docs]
changedir = doc/scapy
deps = sphinx
       sphinx_rtd_theme
commands = sphinx-build -W . _build/html

[testenv:spell]
deps = codespell
# inet6, dhcp6 and the ipynb files contains french: ignore them
commands = codespell --ignore-words=.travis/codespell_ignore.txt --skip="*.pyc,*.png,*.raw,*.pdf,*.pcap,*.js,*.html,*.der,*_build*,*inet6.py,*dhcp6.py,*.ipynb" scapy/ doc/ test/ .github/

[testenv:flake8]
description = "Check Scapy code style & quality"
skip_install = true
deps = flake8
commands = flake8 scapy/

# flake8 configuration
[flake8]
ignore = E731, W504
exclude = scapy/modules/six.py,
          scapy/modules/winpcapy.py
