Skip to content

Commit

Permalink
autotest: run Python tests directly from source tree
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Feb 9, 2024
1 parent 721c775 commit 1ca4e57
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 43 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/alpine_32bit/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ set -e

. ../scripts/setdevenv.sh

export PYTEST="python3 -m pytest -vv -p no:sugar --color=no"
export PYTEST="python3 -m pytest -c pytest.ini -vv -p no:sugar --color=no"
TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest

make quicktest

Expand All @@ -20,11 +21,11 @@ PYTEST_SKIP="gdrivers/jp2openjpeg.py $PYTEST_SKIP"
# Failures for the following tests. See https://github.com/OSGeo/gdal/runs/1425843044

# depends on tiff_ovr.py that is going to be removed below
(cd autotest && $PYTEST utilities/test_gdaladdo.py)
(cd autotest && $PYTEST ${TEST_DIR}/utilities/test_gdaladdo.py)
PYTEST_SKIP="autotest/utilities/test_gdaladdo.py $PYTEST_SKIP"

for i in $PYTEST_XFAIL ; do
(cd autotest && $PYTEST $i || echo "Ignoring failure")
(cd autotest && $PYTEST ${TEST_DIR}/$i || echo "Ignoring failure")
done

(cd autotest && $PYTEST $(echo " $PYTEST_SKIP $PYTEST_XFAIL" | sed -r 's/[[:space:]]+/ --ignore=/g'))
(cd autotest && $PYTEST ${TEST_DIR} $(echo " $PYTEST_SKIP $PYTEST_XFAIL" | sed -r 's/[[:space:]]+/ --ignore=/g'))
8 changes: 5 additions & 3 deletions .github/workflows/asan/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export LD_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)
export ASAN_OPTIONS=allocator_may_return_null=1:symbolize=1:suppressions=$PWD/../autotest/asan_suppressions.txt
export LSAN_OPTIONS=detect_leaks=1,print_suppressions=0,suppressions=$PWD/../autotest/lsan_suppressions.txt

gdalinfo autotest/gcore/data/byte.tif
TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest

gdalinfo ${TEST_DIR}/gcore/data/byte.tif
python3 -c "from osgeo import gdal; print('yes')"

cd autotest
Expand All @@ -26,15 +28,15 @@ cd autotest

echo "#!/bin/sh" > pytest_wrapper.sh
echo 'ARGS="$*"' >> pytest_wrapper.sh
echo "python3 -m pytest --capture=no -ra -vv -p no:sugar --color=no -o console_output_style=classic \${ARGS} 2>&1" >> pytest_wrapper.sh
echo "python3 -m pytest -c pytest.ini --capture=no -ra -vv -p no:sugar --color=no -o console_output_style=classic \${ARGS} 2>&1" >> pytest_wrapper.sh
cat pytest_wrapper.sh
chmod +x pytest_wrapper.sh

# NOTE: `find ... -exec` always exits with 0 even when the tests failed.
# That turns out to be what we want here though, since we want
# to not fail when the address sanitizer finds errors.
# So we tee the output to a file and grep it to discover if the tests failed.
find -L \
find ${TEST_DIR} \
ogr gcore gdrivers osr alg gnm utilities pyscripts \
-name '*.py' \
! -name netcdf_cfchecks.py \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ BENCHMARK_COMPARE_OPTIONS=(
"--benchmark-compare=0001_ref" \
)

(source ${GDAL_SOURCE_DIR:=..}/scripts/setdevenv.sh; pytest autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv || (echo "Retrying..."; pytest autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv))
(source ${GDAL_SOURCE_DIR:=..}/scripts/setdevenv.sh; pytest ${GDAL_SOURCE_DIR:=..}/autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv || (echo "Retrying..."; pytest ${GDAL_SOURCE_DIR:=..}/autotest/benchmark "${BENCHMARK_OPTIONS[@]}" "${BENCHMARK_COMPARE_OPTIONS[@]}" --capture=no -ra -vv))
9 changes: 5 additions & 4 deletions .github/workflows/coverage/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ export PYTEST="python3 -m pytest -vv -p no:sugar --color=no"
. ../scripts/setdevenv.sh

IP=host.docker.internal
TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest

# MySQL 8
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ogr/ogr_mysql.py)
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py)
# MariaDB 10.3.9
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ogr/ogr_mysql.py)
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py)

# PostGIS tests
(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ogr/ogr_pg.py)
(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra gdrivers/postgisraster.py)
(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ${TEST_DIR}/ogr/ogr_pg.py)
(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra ${TEST_DIR}/gdrivers/postgisraster.py)

# Generate coverage report
lcov --directory . --capture --output-file gdal.info 2>/dev/null
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/ubuntu_22.04/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ set -e

. ../scripts/setdevenv.sh

export PYTEST="python3 -m pytest -vv -p no:sugar --color=no"
export PYTEST="python3 -m pytest -c pytest.ini -vv -p no:sugar --color=no"

# Run C++ tests
make quicktest

IP=host.docker.internal
TEST_DIR=${GDAL_SOURCE_DIR:=..}/autotest

# Test /vsiaz/ against the Azurite simulator
export AZURITE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://${IP}:10000/devstoreaccount1;"
AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} python3 -c "from osgeo import gdal; import sys; sys.exit(gdal.Mkdir('/vsiaz/mycontainer', 0o755))"
(cd autotest && AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} AZ_RESOURCE=mycontainer $PYTEST gcore/vsiaz_real_instance_manual.py)
(cd autotest && AZURE_STORAGE_CONNECTION_STRING=${AZURITE_STORAGE_CONNECTION_STRING} AZ_RESOURCE=mycontainer $PYTEST ${TEST_DIR}/gcore/vsiaz_real_instance_manual.py)

# MySQL 8
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ogr/ogr_mysql.py)
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33060,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py)
# MariaDB 10.3.9
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ogr/ogr_mysql.py)
(cd autotest && OGR_MYSQL_CONNECTION_STRING=mysql:test,user=root,password=passwd,port=33061,host=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mysql.py)

# PostGIS tests
(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ogr/ogr_pg.py)
(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra gdrivers/postgisraster.py)
(cd autotest && OGR_PG_CONNECTION_STRING="host=$IP port=25432 dbname=autotest user=docker password=docker" $PYTEST --capture=no -ra ${TEST_DIR}/ogr/ogr_pg.py)
(cd autotest && PGHOST="$IP" PGPORT=25432 PGUSER=docker PGPASSWORD=docker $PYTEST --capture=no -ra ${TEST_DIR}/gdrivers/postgisraster.py)

# MongoDB v3
(cd autotest && MONGODBV3_TEST_PORT=27018 MONGODBV3_TEST_HOST=$IP $PYTEST ogr/ogr_mongodbv3.py)
(cd autotest && MONGODBV3_TEST_PORT=27018 MONGODBV3_TEST_HOST=$IP $PYTEST ${TEST_DIR}/ogr/ogr_mongodbv3.py)

(cd autotest && OGR_MSSQL_CONNECTION_STRING="MSSQL:server=$IP;database=TestDB;driver=ODBC Driver 17 for SQL Server;UID=SA;PWD=DummyPassw0rd" $PYTEST ogr/ogr_mssqlspatial.py)
(cd autotest && OGR_MSSQL_CONNECTION_STRING="MSSQL:server=$IP;database=TestDB;driver=ODBC Driver 17 for SQL Server;UID=SA;PWD=DummyPassw0rd" $PYTEST ${TEST_DIR}/ogr/ogr_mssqlspatial.py)

(cd autotest && $PYTEST)
(cd autotest && $PYTEST ${TEST_DIR})
26 changes: 4 additions & 22 deletions autotest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,8 @@ function (symlink_or_copy source destination)
endif ()
endfunction ()

symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/conftest.py ${CMAKE_CURRENT_BINARY_DIR}/conftest.py)
symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/run_slow_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/run_slow_tests.sh)

if (NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
foreach (subdir IN ITEMS pymod proj_grids cpp/data)
if (SKIP_COPYING_AUTOTEST_SUBDIRS)
message(STATUS "Skipping copying ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}")
else ()
symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${subdir})
endif ()
endforeach ()
endif()

foreach (
tgt IN
ITEMS ogr
Expand All @@ -94,20 +83,13 @@ endfunction ()
utilities
benchmark
slow_tests)
if (NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
if (SKIP_COPYING_AUTOTEST_SUBDIRS)
message(STATUS "Skipping copying ${CMAKE_CURRENT_SOURCE_DIR}/${tgt}")
else ()
symlink_or_copy(${CMAKE_CURRENT_SOURCE_DIR}/${tgt} ${CMAKE_CURRENT_BINARY_DIR}/${tgt})
endif ()
endif()
add_custom_target(
autotest_${tgt}
COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} ${Python_EXECUTABLE} -m pytest -c
${CMAKE_CURRENT_BINARY_DIR}/pytest.ini ${tgt}
${CMAKE_CURRENT_LIST_DIR}/pytest.ini ${CMAKE_CURRENT_LIST_DIR}/${tgt}
DEPENDS ${GDAL_LIB_TARGET_NAME} gdalapps python_binding)
add_test(NAME autotest_${tgt} COMMAND ${Python_EXECUTABLE} -m pytest -c ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini
${tgt})
add_test(NAME autotest_${tgt}
COMMAND ${Python_EXECUTABLE} -m pytest -c ${CMAKE_CURRENT_BINARY_DIR}/pytest.ini ${CMAKE_CURRENT_LIST_DIR}/${tgt})
set_property(TEST autotest_${tgt} PROPERTY ENVIRONMENT "${PYTHON_RUN_ENV}")
endforeach ()
add_custom_target(
Expand Down Expand Up @@ -175,7 +157,7 @@ int main(int argc, char **argv) {
COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_RUN_ENV} $<TARGET_FILE:pytest_runner> -c
${CMAKE_CURRENT_BINARY_DIR}/pytest.ini
DEPENDS ${GDAL_LIB_TARGET_NAME} gdalapps python_binding pytest_runner
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
endif ()

endif ()

0 comments on commit 1ca4e57

Please sign in to comment.