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

# Configuration file for quick / short tests.
# Use tox_slow.ini for longer running tests.

[tox]
envlist = py37, py38, py39, py310, flake8

[testenv]
# make sure those variables are passed down; you should define 
# either explicitly the RDIFF_TEST_* variables or rely on the current
# user being correctly identified (which might not happen in a container)
passenv = RDIFF_TEST_*, RDIFF_BACKUP_*
setenv =
# paths for coverage must be absolute so that sub-processes find them
# even if they're started from another location.
	COVERAGE_FILE = {envlogdir}/coverage.sqlite
	COVERAGE_PROCESS_START = {toxinidir}/tox.ini
deps = -r{toxinidir}/requs/base.txt
       -r{toxinidir}/requs/optional.txt
       -r{toxinidir}/requs/test.txt
allowlist_externals = sh
commands_pre =
	rdiff-backup --version
# must be the first command to setup the test environment
	python testing/commontest.py
	coverage erase
# write the hook file which will make sure that coverage is loaded
# also for sub-processes, like for "client/server" rdiff-backup
	python -c 'with open("{envsitepackagesdir}/coverage.pth","w") as fd: fd.write("import coverage; coverage.process_startup()\n")'
commands =
	coverage run testing/action_backuprestore_test.py --verbose --buffer
	coverage run testing/action_calculate_test.py --verbose --buffer
	coverage run testing/action_compare_test.py --verbose --buffer
	coverage run testing/action_complete_test.py --verbose --buffer
	coverage run testing/action_list_test.py --verbose --buffer
	coverage run testing/action_regress_test.py --verbose --buffer
	coverage run testing/action_remove_test.py --verbose --buffer
	coverage run testing/action_test_test.py --verbose --buffer
	coverage run testing/action_verify_test.py --verbose --buffer
	sh ./testing/verbosity_actions_test.sh 9 --verbose --buffer
	coverage run testing/api_test.py --verbose --buffer
	coverage run testing/location_map_filenames_test.py --verbose --buffer
	coverage run testing/location_map_hardlinks_test.py --verbose --buffer
	coverage run testing/location_lock_test.py --verbose --buffer
	coverage run testing/utils_simpleps_test.py --verbose --buffer
	coverage run testing/ctest.py --verbose --buffer
	coverage run testing/timetest.py --verbose --buffer
	coverage run testing/librsynctest.py --verbose --buffer
	coverage run testing/statisticstest.py --verbose --buffer
	coverage run testing/user_grouptest.py --verbose --buffer
	coverage run testing/setconnectionstest.py --verbose --buffer
	coverage run testing/iterfiletest.py --verbose --buffer
	coverage run testing/longnametest.py --verbose --buffer
	coverage run testing/robusttest.py --verbose --buffer
	coverage run testing/connectiontest.py --verbose --buffer
	coverage run testing/incrementtest.py --verbose --buffer
	coverage run testing/hardlinktest.py --verbose --buffer
	coverage run testing/eas_aclstest.py --verbose --buffer
	coverage run testing/FilenameMappingtest.py --verbose --buffer
	coverage run testing/fs_abilitiestest.py --verbose --buffer
	coverage run testing/hashtest.py --verbose --buffer
	coverage run testing/selectiontest.py --verbose --buffer
	coverage run testing/metadatatest.py --verbose --buffer
	coverage run testing/rpathtest.py --verbose --buffer
	coverage run testing/rorpitertest.py --verbose --buffer
	coverage run testing/rdifftest.py --verbose --buffer
	coverage run testing/securitytest.py --verbose --buffer
	coverage run testing/killtest.py --verbose --buffer
	coverage run testing/backuptest.py --verbose --buffer
	coverage run testing/comparetest.py --verbose --buffer
	coverage run testing/regresstest.py --verbose --buffer
	coverage run testing/restoretest.py --verbose --buffer
	coverage run testing/cmdlinetest.py --verbose --buffer
	coverage run testing/rdiffbackupdeletetest.py --verbose --buffer
	coverage run testing/errorsrecovertest.py --verbose --buffer
	coverage run testing/rdb_arguments.py --verbose --buffer
# can only work on OS/X TODO later
#	coverage run testing/resourceforktest.py

# combine all coverage results and show the summary
	coverage combine
	coverage report

[testenv:flake8]
deps = -r{toxinidir}/requs/test.txt
commands_pre=
commands =
	flake8 setup.py src testing tools

[flake8]
ignore =
	# line too long (86 > 79 characters)
	E501
	# line break before binary operator
	W503
filename =
	*.py,
	src/rdiff-backup*
exclude =
    .git
    .tox
    .tox.root
    __pycache__
    build
max-complexity = 20

[coverage:run]
parallel = True
source =
	rdiff_backup
	rdiffbackup

[coverage:report]
skip_empty = True
fail_under = 80
sort = Cover
