# 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 = py, 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_*, LIBRSYNC_DIR
deps = -r{toxinidir}/requs/base.txt
       -r{toxinidir}/requs/optional.txt
whitelist_externals = cmd
commands_pre =
    rdiff-backup --version
    # must be the first command to setup the test environment
    python testing/commontest.py
commands =
# The commented tests do not run on Windows yet and will be fixed & uncommented one by one
    python testing/action_backuprestore_test.py --verbose --buffer
    python testing/action_calculate_test.py --verbose --buffer
    python testing/action_compare_test.py --verbose --buffer
    python testing/action_list_test.py --verbose --buffer
    python testing/action_regress_test.py --verbose --buffer
    python testing/action_remove_test.py --verbose --buffer
    python testing/action_test_test.py --verbose --buffer
    python testing/action_verify_test.py --verbose --buffer
    python testing/api_test.py --verbose --buffer
    python testing/location_map_filenames_test.py --verbose --buffer
#    python testing/location_map_hardlinks_test.py --verbose --buffer
    python testing/location_lock_test.py --verbose --buffer
    python testing/utils_simpleps_test.py --verbose --buffer
    python testing/ctest.py
    python testing/timetest.py
#    python testing/librsynctest.py  # rdiff binary is missing
    python testing/statisticstest.py
#    python testing/user_grouptest.py   # no module named pwd under Windows
    python testing/setconnectionstest.py  # backslashes interpreted differently
    python testing/iterfiletest.py
#    python testing/longnametest.py  # handling of long filenames too different
    python testing/robusttest.py
    python testing/connectiontest.py
    python testing/incrementtest.py  # skipping symlinks
#    python testing/hardlinktest.py  # too many path errors
#    python testing/eas_aclstest.py  # no module named pwd under Windows
#    python testing/FilenameMappingtest.py  # issues with : in date/time-string
#    python testing/fs_abilitiestest.py  # module 'os' has no attribute 'getuid'
    python testing/hashtest.py
    python testing/selectiontest.py
#    python testing/metadatatest.py  # issues with : in date/time/string
    python testing/rpathtest.py
    python testing/rorpitertest.py
    python testing/rdifftest.py
#    python testing/securitytest.py  # no os.getuid + backslash in path handlingon --server
#    python testing/killtest.py  # cannot create symbolic link
#    python testing/backuptest.py  # No module named rdiff_backup in server.py
    python testing/comparetest.py
#    python testing/regresstest.py  # issue with : in date/time/string
#    python testing/restoretest.py  # too many issues to count
#    python testing/cmdlinetest.py  # too many issues to count
#    python testing/rdiffbackupdeletetest.py  # not written to run under Windows
#    python testing/errorsrecovertest.py  # FIXME pipeline has become unstable
    python testing/rdb_arguments.py --verbose --buffer
# can only work on OS/X TODO later
#    python testing/resourceforktest.py

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

[flake8]
ignore =
    # line too long (86 > 79 characters)
    E501
    # line break before binary operator
    W503
exclude =
    .git
    .tox
    .tox.root
    __pycache__
    build
max-complexity = 40

[testenv:buildexe]
deps = -r{toxinidir}/requs/base.txt
       -r{toxinidir}/requs/optional.txt
       -r{toxinidir}/requs/build.txt
# add hook file to hooks-dir for each new plugin manager!
commands =
    python setup.py bdist_wheel
    pyinstaller --onefile --distpath build/{env:RDIFF_BACKUP_VERSION} \
        --additional-hooks-dir=tools \
        --console {envsitepackagesdir}/rdiffbackup/run.py \
        --name rdiff-backup \
        --copy-metadata rdiff-backup
