#!/bin/bash cd "$(dirname "$0")" rm -f run_functional_tests.log show_help() { cat </dev/null 2>/dev/null } test_script="./scripts/functional_tests.py" report_file="run_functional_tests.html" coverage_arg="" xunit_report_file="" structured_data_report_file="" structured_data_html=0 SKIP_CLIENT_BUILD=${GALAXY_SKIP_CLIENT_BUILD:-1} if [ "$SKIP_CLIENT_BUILD" = "1" ]; then skip_client_build="--skip-client-build" else skip_client_build="" fi # If in Jenkins environment, create xunit-${BUILD_NUMBER}.xml by default. if [ -n "$BUILD_NUMBER" ]; then xunit_report_file="xunit-${BUILD_NUMBER}.xml" fi run_default_functional_tests="1" # Loop through and consume the main arguments. # Some loops will consume more than one argument (there are extra "shift"s in some cases). while : do case "$1" in -h|--help|-\?) show_help exit 0 ;; -l|-list|--list) show_list exit 0 ;; -id|--id) if [ $# -gt 1 ]; then test_id=$2; shift 2 else echo "--id requires an argument" 1>&2 exit 1 fi ;; -s|-sid|--sid) if [ $# -gt 1 ]; then section_id=$2 shift 2 else echo "--sid requires an argument" 1>&2 exit 1 fi ;; -a|-api|--api) GALAXY_TEST_USE_HIERARCHICAL_OBJECT_STORE="True" # Run these tests with a non-trivial object store. export GALAXY_TEST_USE_HIERARCHICAL_OBJECT_STORE GALAXY_TEST_TOOL_CONF="lib/galaxy/config/sample/tool_conf.xml.sample,test/functional/tools/samples_tool_conf.xml" marker="not cwl_conformance" test_script="pytest" report_file="./run_api_tests.html" if [ $# -gt 1 ]; then api_script=$2 shift 2 else api_script="./lib/galaxy_test/api" shift 1 fi ;; -cwl|--cwl) GALAXY_TEST_USE_HIERARCHICAL_OBJECT_STORE="True" # Run these tests with a non-trivial object store. export GALAXY_TEST_USE_HIERARCHICAL_OBJECT_STORE GALAXY_TEST_TOOL_CONF="lib/galaxy/config/sample/tool_conf.xml.sample,test/functional/tools/samples_tool_conf.xml" marker="cwl_conformance" test_script="pytest" report_file="./run_cwl_tests.html" generate_cwl_conformance_tests=1 if [ $# -gt 1 ]; then api_script=$2 shift 2 else api_script="./lib/galaxy_test/api/cwl" shift 1 fi ;; -selenium|--selenium) GALAXY_TEST_TOOL_CONF="lib/galaxy/config/sample/tool_conf.xml.sample,test/functional/tools/samples_tool_conf.xml" test_script="pytest" report_file="./run_selenium_tests.html" skip_client_build="" if [ $# -gt 1 ]; then selenium_script=$2 shift 2 else selenium_script="./lib/galaxy_test/selenium" shift 1 fi ;; -t|-toolshed|--toolshed) test_script="./lib/tool_shed/test/functional_tests.py" report_file="run_toolshed_tests.html" if [ $# -gt 1 ]; then toolshed_script=$2 shift 2 else toolshed_script="./lib/tool_shed/test/functional" shift 1 fi ;; -clean_pyc|--clean_pyc) find lib -iname '*pyc' -exec rm -rf {} \; find test -iname '*pyc' -exec rm -rf {} \; shift ;; -skip_flakey_fails|--skip_flakey_fails) GALAXY_TEST_SKIP_FLAKEY_TESTS_ON_ERROR=1 export GALAXY_TEST_SKIP_FLAKEY_TESTS_ON_ERROR shift ;; --external_url) export GALAXY_TEST_EXTERNAL=$2 shift 2 ;; --external_master_key) export GALAXY_CONFIG_MASTER_API_KEY=$2 shift 2 ;; --external_user_key) export GALAXY_TEST_USER_API_KEY=$2 shift 2 ;; -f|-framework|--framework) GALAXY_TEST_TOOL_CONF="test/functional/tools/samples_tool_conf.xml" marker="tool" test_script="pytest" report_file="run_framework_tests.html" framework_test=1; shift 1 ;; -main|-main_tools|--main_tools) GALAXY_TEST_TOOL_CONF="lib/galaxy/config/sample/tool_conf.xml.sample" marker="tool" test_script="pytest" report_file="run_framework_tests.html" framework_test=1; shift 1 ;; -d|-data_managers|--data_managers) marker="data_manager" test_script="pytest" report_file="run_data_managers_tests.html" data_managers_test=1; shift 1 ;; -m|-migrated|--migrated) GALAXY_TEST_TOOL_CONF="config/migrated_tools_conf.xml" marker="tool" test_script="pytest" report_file="run_migrated_tests.html" migrated_test=1; shift ;; -installed|--installed) GALAXY_TEST_TOOL_CONF="config/shed_tool_conf.xml" marker="tool" test_script="pytest" report_file="run_installed_tests.html" installed_test=1; shift ;; -r|--report_file) if [ $# -gt 1 ]; then report_file=$2 shift 2 else echo "--report_file requires an argument" 1>&2 exit 1 fi ;; --xunit_report_file) if [ $# -gt 1 ]; then xunit_report_file=$2 shift 2 else echo "--xunit_report_file requires an argument" 1>&2 exit 1 fi ;; --structured_data_report_file) if [ $# -gt 1 ]; then structured_data_report_file=$2 shift 2 else echo "--structured_data_report_file requires an argument" 1>&2 exit 1 fi ;; --structured_data_html) structured_data_html=1 shift ;; --verbose_errors) GALAXY_TEST_VERBOSE_ERRORS=True export GALAXY_TEST_VERBOSE_ERRORS shift ;; --ci_test_metrics) GALAXY_CONFIG_OVERRIDE_STATSD_PREFIX="galaxy" export GALAXY_CONFIG_OVERRIDE_STATSD_PREFIX GALAXY_CONFIG_OVERRIDE_STATSD_HOST="localhost" export GALAXY_CONFIG_OVERRIDE_STATSD_HOST GALAXY_CONFIG_OVERRIDE_STATSD_INFLUXDB="true" export GALAXY_CONFIG_OVERRIDE_STATSD_INFLUXDB GALAXY_CONFIG_OVERRIDE_DATABASE_LOG_QUERY_COUNTS="true" export GALAXY_CONFIG_OVERRIDE_DATABASE_LOG_QUERY_COUNTS GALAXY_CONFIG_OVERRIDE_ENABLE_PER_REQUEST_SQL_DEBUGGING="true" export GALAXY_CONFIG_OVERRIDE_ENABLE_PER_REQUEST_SQL_DEBUGGING GALAXY_CONFIG_OVERRIDE_STATSD_MOCK_CALLS="true" export GALAXY_CONFIG_OVERRIDE_STATSD_MOCK_CALLS shift ;; -c|--coverage) # Must have coverage installed (try `which coverage`) - only works with pytest # for now. Would be great to get this to work with functional tests though. coverage_arg="--with-coverage" shift ;; --debug) #TODO ipdb would be nicer. NOSE_PDB=True export NOSE_PDB shift ;; -u|-unit|--unit) report_file="run_unit_tests.html" test_script="pytest" unit_extra='--doctest-modules --ignore lib/galaxy/web/proxy/js/node_modules/ --ignore lib/tool_shed/webapp/controllers --ignore lib/galaxy/jobs/runners/chronos.py --ignore lib/tool_shed/webapp/model/migrate --ignore lib/galaxy/tools/bundled --ignore lib/galaxy_test --ignore lib/tool_shed/test' if [ $# -gt 1 ]; then unit_extra="$unit_extra $2" shift 2 else unit_extra="$unit_extra lib test/unit" shift 1 fi ;; -i|-integration|--integration) GALAXY_TEST_TOOL_CONF="lib/galaxy/config/sample/tool_conf.xml.sample,test/functional/tools/samples_tool_conf.xml" test_script="pytest" report_file="./run_integration_tests.html" if [ $# -gt 1 ]; then integration_extra=$2 shift 2 else integration_extra="./test/integration" shift 1 fi ;; --no_cleanup) GALAXY_TEST_NO_CLEANUP=1 export GALAXY_TEST_NO_CLEANUP TOOL_SHED_TEST_NO_CLEANUP=1 export TOOL_SHED_TEST_NO_CLEANUP GALAXY_INSTALL_TEST_NO_CLEANUP=1 export GALAXY_INSTALL_TEST_NO_CLEANUP echo "Skipping Python test clean up." shift ;; --skip-venv) skip_venv='--skip-venv' shift ;; --no-create-venv) no_create_venv='--no-create-venv' shift ;; --no-replace-pip) no_replace_pip='--no-replace-pip' shift ;; --replace-pip) replace_pip='--replace-pip' shift ;; --skip-common-startup) # Don't run ./scripts/common_startup.sh (presumably it has already # been done, or you know what you're doing). skip_common_startup=1 shift ;; --) # Do not default to running the functional tests in this case, caller # is opting to run specific tests so don't interfere with that by default. unset run_default_functional_tests; shift break ;; -*) echo "invalid option: $1" 1>&2; show_help exit 1 ;; *) if [ -n "$1" ]; then test_target="$1" shift fi # Maybe we shouldn't break here but for now to pass more than one argument to the # underlying test driver (scripts/nosetests.py) use -- instead. break ;; esac done if [ -z "$skip_common_startup" ]; then if [ -n "$GALAXY_TEST_DBURI" ]; then GALAXY_CONFIG_OVERRIDE_DATABASE_CONNECTION=$GALAXY_TEST_DBURI export GALAXY_CONFIG_OVERRIDE_DATABASE_CONNECTION fi ./scripts/common_startup.sh $skip_venv $no_create_venv $no_replace_pip $replace_pip $skip_client_build --dev-wheels || exit 1 unset GALAXY_CONFIG_OVERRIDE_DATABASE_CONNECTION fi . ./scripts/common_startup_functions.sh setup_python if [ -n "$framework_test" ] || [ -n "$installed_test" ] || [ -n "$migrated_test" ] || [ -n "$data_managers_test" ] ; then if [ -n "$test_id" ]; then selector="-k $test_id" else selector="" fi extra_args="test/functional/test_toolbox_pytest.py $selector" elif [ -n "$selenium_script" ]; then extra_args="$selenium_script" elif [ -n "$toolshed_script" ]; then extra_args="$toolshed_script" elif [ -n "$api_script" ]; then extra_args="$api_script" elif [ -n "$section_id" ]; then extra_args=$(python tool_list.py "$section_id") elif [ -n "$unit_extra" ]; then extra_args="$unit_extra" elif [ -n "$integration_extra" ]; then extra_args="$integration_extra" elif [ -n "$test_target" ] ; then extra_args="$test_target" elif [ -n "$run_default_functional_tests" ] ; then extra_args='--exclude="^get" functional' else extra_args="" fi if [ -n "$xunit_report_file" ]; then if [ "$test_script" = 'pytest' ]; then xunit_args="--junit-xml $xunit_report_file" else xunit_args="--with-xunit --xunit-file $xunit_report_file" fi else xunit_args="" fi if [ -n "$structured_data_report_file" ]; then if [ "$test_script" = 'pytest' ]; then structured_data_args="--json-report --json-report-file $structured_data_report_file" else structured_data_args="--with-structureddata --structured-data-file $structured_data_report_file" fi else structured_data_args="" fi if [ -n "$generate_cwl_conformance_tests" ]; then make generate-cwl-conformance-tests fi export GALAXY_TEST_TOOL_CONF if [ "$test_script" = 'pytest' ]; then if [ "$coverage_arg" = '--with-coverage' ]; then coverage_arg="--cov-report term --cov=lib" fi if [ -n "$marker" ]; then marker_args=(-m "$marker") else marker_args=() fi args=(-v $structured_data_args --html "$report_file" --self-contained-html $coverage_arg $xunit_args $extra_args "${marker_args[@]}" "$@") "$test_script" "${args[@]}" else python "$test_script" $coverage_arg -v --with-nosehtml --html-report-file $report_file $xunit_args $structured_data_args $extra_args "$@" fi exit_status=$? echo "Testing complete. HTML report is in \"$report_file\"." 1>&2 if [ "$structured_data_html" = '1' ]; then python scripts/tests_markdown.py --output_path "${structured_data_report_file%.json}.html" "$structured_data_report_file" fi exit ${exit_status}