#!/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 that require a configured interface, network access, Usenet
	# server credentials, or are only relevant for internal upstream use.
	#
	# In addition, a few tests have been (temporarily) disabled because of other issues:
	# test_queue_repair: too flaky
	# test_functional_config.py: recent chrome/selenium too unreliable
	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_cfg.py::TestValidators::test_validate_host \
		--deselect=tests/test_newswrapper.py::TestNewsWrapper::test_socket_binding_outgoing_ip \
		--deselect=tests/test_rss.py::TestRSS::test_rss_newznab_parser \
		--deselect=tests/test_rss.py::TestRSS::test_rss_nzedb_parser \
		--deselect=tests/test_urlgrabber.py::TestBuildRequest::test_http_basic \
		--deselect=tests/test_urlgrabber.py::TestBuildRequest::test_https_basic \
		--ignore=tests/test_consistency.py \
		--ignore=tests/test_functional_downloads.py \
		--ignore=tests/test_functional_config.py \
		--ignore=tests/test_internetspeed.py \
		--ignore=tests/test_get_addrinfo.py
done
