#! /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=()

# * Two bytecode tests fail on Python 3.10, so we exclude those too.
# Reported upstream to
# https://github.com/fabioz/PyDev.Debugger/issues/222
EXCLUDES+=(
    tests_python/test_bytecode_manipulation.py::test_set_pydevd_break_01
    tests_python/test_bytecode_manipulation.py::test_set_pydevd_break_01a
)

# * 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)

# * 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)

# 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_a
        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.py::test_gevent_show_paused_greenlets[True]
        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[*]}
