#!/bin/sh

set -e -u -x

cp -r tests "$AUTOPKGTEST_TMP"
# Copy pyproject.toml because is used by the test_check_valid test.
cp pyproject.toml "$AUTOPKGTEST_TMP" 
cd "$AUTOPKGTEST_TMP"

TEST_EXPR="\
not test_self_update_should_install_all_necessary_elements \
and not test_add_file_constraint_sdist \
and not test_add_file_constraint_sdist_old_installer \
and not test_publish_dry_run \
and not test_info_from_sdist \
and not test_installer_can_install_dependencies_from_forced_source \
and not test_search_for_file_sdist \
and not test_search_for_file_sdist_with_extras \
and not test_solver_can_resolve_sdist_dependencies \
and not test_solver_can_resolve_sdist_dependencies_with_extras \
and not test_solver_chooses_from_correct_repository_if_forced \
and not test_solver_chooses_from_correct_repository_if_forced_and_transitive_dependency \
and not test_solver_does_not_choose_from_secondary_repository_by_default \
and not test_solver_chooses_from_secondary_if_explicit \
and not test_get_package_information_fallback_read_setup \
and not test_get_package_information_skips_dependencies_with_invalid_constraints \
and not test_get_package_retrieves_packages_with_no_hashes \
and not test_fallback_can_read_setup_to_get_dependencies \
and not test_exporter_can_export_requirements_txt_with_file_packages \
and not test_exporter_can_export_requirements_txt_with_file_packages_and_markers \
and not test_lock_no_update \
and not test_locker_dumps_dependency_information_correctly \
and not test_package_partial_yank \
and not test_run_installs_with_same_version_url_files \
and not test_env_info_displays_complete_info \
and not test_skip_existing_output \
and not test_installer_should_use_the_locked_version_of_git_dependencies_with_extras \
and not test_installer_should_use_the_locked_version_of_git_dependencies_without_reference \
and not test_installer_uses_prereleases_if_they_are_compatible \
and not test_requirement_git_subdirectory \
and not test_check_valid \
and not test_check_invalid \
and not test_packages_property_returns_empty_list \
and not test_parse_dependency_specification \
and not test_info_setup_missing_mandatory_should_trigger_pep517 \
and not test_uninstall_git_package_nspkg_pth_cleanup \
and not test_executor_should_write_pep610_url_references_for_directories \
and not test_executor_should_write_pep610_url_references_for_git \
and not test_executor_should_write_pep610_url_references_for_git_with_subdirectories \
and not test_builder_setup_generation_runs_with_pip_editable \
and not test_executor_should_write_pep610_url_references_for_non_wheel_urls \
and not test_executor_should_write_pep610_url_references_for_non_wheel_files \
and not test_prepare_sdist \
and not test_shell \
and not test_chooser_md5_remote_fallback_to_sha256_inline_calculation \
and not test_solver_ignores_explicit_repo_for_transient_dependencies \
and not test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess \
and not test_build_backend_errors_are_reported_correctly_if_caused_by_subprocess_encoding \
and not test_isolated_env_install_success \
and not test_isolated_env_install_error \
and not test_isolated_env_install_failure \
and not test_application_with_plugins \
and not test_build_system_requires_not_available \
and not test_build_system_requires_install_failure \
and not test_installer_with_pypi_repository \
and not test_prepare_directory \
and not test_prepare_directory_with_extensions \
and not test_prepare_directory_editable \
and not test_prepare_directory_script \
and not test_fallback_on_detect_active_python \
and not test_get_venv_with_venv_folder_present \
and not test_not_fresh_lock \
and not test_list \
and not test_info_setup_complex_calls_script \
and not test_publish_dist_dir_option \
and not test_executor_known_hashes \
and not test_execute_executes_a_batch_of_operations \
and not test_execute_prints_warning_for_yanked_package \
and not test_build_environment_called_build_script_specified \
and not test_solver_ignores_explicit_repo_for_transitive_dependencies \
and not test_file_hashes_returns_none_for_blake2_with_fips \
and not test_solver_does_not_choose_from_supplemental_repository_by_default \
and not test_get_preferred_python_use_poetry_python_disabled \
and not test_solver_chooses_from_supplemental_if_explicit \
and not test_file_hashes_returns_none_for_md5_with_fips \
and not test_file_hashes_returns_proper_hashes_for_file \
and not test_env_system_packages_are_relative_to_lib \
and not test_shutil_which_python_provider"

case "$(dpkg --print-architecture)" in
    amd64|arm64|i386) ;;
    *)
        # pbs_installer does not advertise any Python builds for these
        # architectures, so the tests won't find any.
        TEST_EXPR="$TEST_EXPR and not test_find_downloadable_versions"
        ;;
esac

for py in $(py3versions -s); do
    $py -m pytest \
        --ignore=tests/console/commands/env/test_list.py \
        --ignore=tests/console/commands/env/test_remove.py \
        --ignore=tests/console/commands/env/test_use.py \
        --ignore=tests/utils/test_env.py \
        --ignore=tests/config/test_config.py \
        --ignore=tests/utils/test_helpers.py \
        -k "$TEST_EXPR" -v 2>&1
done
