#! /bin/bash

# Some of the tests must be excluded across all architectures for
# a variety of reasons.

# This script is called from both debian/rules and from the
# autopkgtest suite.

# * Some of the tests depend on the uninstalled pycompletionserver.py
# or pydev_coverage.py, so we ignore those; if they are only deselected,
# pytest collection fails as the imports fail
IGNORES=(
    --ignore=tests/test_jyserver.py
    --ignore=tests/test_pyserver.py
    --ignore=tests_python/test_pydevcoverage.py
)

# The rest will be excluded
EXCLUDES=()

# * test_case_flask_exceptions fails, and is not tested by upstream,
# so we just skip it.
# Reported upstream to
# https://github.com/fabioz/PyDev.Debugger/issues/223
EXCLUDES+=(tests_python/test_debugger_json.py::test_case_flask_exceptions)

# * Two flask tests fail with Flask 2.2.2, so we exclude those.
# Reported upstream to https://github.com/fabioz/PyDev.Debugger/issues/229
EXCLUDES+=(
    tests_python/test_debugger.py::test_case_flask
    tests_python/test_debugger_json.py::test_case_flask_line_validation
)

# * test_py_37_breakpoint_remote_no_import does not work on the built
# or installed version; reported upstream to
# https://github.com/fabioz/PyDev.Debugger/issues/224
EXCLUDES+=(tests_python/test_debugger.py::test_py_37_breakpoint_remote_no_import)

# With recent versions of Python 3.10 and/or some updated libraries,
# test_gevent_show_paused_greenlets[True] now fails on amd64 as well
# as other architectures.  Reported upstream to
# https://github.com/fabioz/PyDev.Debugger/issues/236
EXCLUDES+=(tests_python/test_debugger.py::test_gevent_show_paused_greenlets[True])

# Numerous tests fail on Python 3.11
# https://github.com/fabioz/PyDev.Debugger/issues/240
EXCLUDES+=(
    tests_python/test_debugger.py::test_case_django_a
    tests_python/test_debugger.py::test_case_qthread1
    tests_python/test_debugger.py::test_case_qthread2
    tests_python/test_debugger.py::test_case_qthread3
    tests_python/test_debugger.py::test_case_qthread4
    tests_python/test_debugger.py::test_multiprocessing_simple[_debugger_case_python_c.py]
    tests_python/test_debugger.py::test_subprocess_quoted_args[_debugger_case_quoting.py]
    tests_python/test_debugger.py::test_subprocess_quoted_args[_debugger_case_subprocess_zip.py]
    tests_python/test_debugger.py::test_remote_debugger_multi_proc[True]
    tests_python/test_debugger.py::test_remote_debugger_multi_proc[False]
    tests_python/test_debugger_json.py::test_subprocess_pydevd_customization[]
    tests_python/test_debugger_json.py::test_subprocess_pydevd_customization[--use-c-switch]
    tests_python/test_debugger_json.py::test_subprocess_pydevd_customization[--posix-spawn]
    tests_python/test_debugger_json.py::test_subprocess_then_fork
    tests_python/test_debugger_json.py::test_no_subprocess_patching[True]
    tests_python/test_debugger_json.py::test_logging_api
)

# Some tests fail intermittently or consistently on some
# architectures; we therefore perform a per-architecture exclusion.
# Since upstream only officially supports amd64 and i386, we have not
# reported these upstream.  Also see README.Debian.

arch=$(dpkg --print-architecture)

if [ $arch = mipsel -o $arch = mips64el -o $arch = armel ]
then
    EXCLUDES+=(
        tests_python/test_debugger.py::test_attach_to_pid_no_threads[True]
        tests_python/test_debugger.py::test_case_django_b
        tests_python/test_debugger.py::test_case_django_invalid_template_exception_breakpoint
        tests_python/test_debugger.py::test_case_django_no_attribute_exception_breakpoint
        tests_python/test_debugger.py::test_case_django_no_attribute_exception_breakpoint_and_regular_exceptions
        tests_python/test_debugger.py::test_case_django_no_var_error
        tests_python/test_debugger.py::test_case_django_template_inherits_no_exception
        tests_python/test_debugger.py::test_case_flask
        tests_python/test_debugger_json.py::test_attach_to_pid[True]
	tests_python/test_debugger_json.py::test_case_django_line_validation
        tests_python/test_debugger_json.py::test_case_django_no_attribute_exception_breakpoint
        tests_python/test_debugger_json.py::test_case_flask_line_validation
        tests_python/test_debugger_json.py::test_code_reload
    )
fi

if [ $arch = ppc64el ]
then
    EXCLUDES+=(
	tests_python/test_debugger_json.py::test_code_reload
    )
fi

DESELECTS=()
for test in "${EXCLUDES[@]}"
do
    DESELECTS+=("--deselect=$test")
done

echo ${IGNORES[*]} ${DESELECTS[*]}
