#!/bin/sh

set -e -u

SOURCE_DIR="$(pwd)"

for py in $(py3versions -s); do
	cd "$AUTOPKGTEST_TMP"
	rm -rf *
	cp -a "$SOURCE_DIR"/tests "$SOURCE_DIR"/scripts "$AUTOPKGTEST_TMP"/

	echo "Running testsuite with $py:"
	# Deselect or ignore some tests:
	# test_validate_host: intermittent failure (network/dns config?)
	# test_publicipv4: requires a configured interface and network access
	# test_extract_pot: only relevant for internal upstream use
	# test_functional_downloads: needs network access and usenet server credentials
	# test_happyeyeballs, test_internetspeed.py: needs network access
	# test_queue_repair: too flaky
	# test_consistency.py: intended for internal upstream use
	# test_functional_config.py: recent chrome/selenium too unreliable
	# test_socket_binding_outgoing_ip: pukes with nonstandard CI network setups
	CI=TRUE PYTHONPATH=/usr/share/sabnzbdplus $py -m pytest \
		--deselect=tests/test_getipaddress.py::TestGetIpAddress::test_publicipv4 \
		--deselect=tests/test_functional_misc.py::TestExtractPot::test_extract_pot \
		--deselect=tests/test_filesystem.py::TestCreateAllDirs::test_permissions_450 \
                --deselect=tests/test_filesystem.py::TestGetUniqueDirFilename::test_nonexistent_dir_without_permission \
		--deselect=tests/test_urlgrabber.py::TestBuildRequest::test_http_params_etc \
		--deselect=tests/test_functional_misc.py::TestQueueRepair::test_queue_repair \
		--deselect=tests/test_newsunpack.py::TestPar2Repair::test_basic \
		--deselect=tests/test_cfg.py::TestValidators::test_validate_host \
		--deselect=tests/test_newswrapper.py::TestNewsWrapper::test_socket_binding_outgoing_ip \
		--ignore=tests/test_consistency.py \
		--ignore=tests/test_functional_downloads.py \
		--ignore=tests/test_functional_config.py \
		--ignore=tests/test_happyeyeballs.py \
		--ignore=tests/test_internetspeed.py
done
