From 0c4527732171b29ff441b3fd4084540a787a6651 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 3 Sep 2021 15:51:50 +0200 Subject: [PATCH] autotest: ogr_gpsbabel.py: skip if build lacks Expat support (fixes #4420) --- autotest/ogr/ogr_gpsbabel.py | 23 +++++++++++++++-------- autotest/ogr/ogr_gpx.py | 8 +++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/autotest/ogr/ogr_gpsbabel.py b/autotest/ogr/ogr_gpsbabel.py index de1e5343593e..68786bb4c956 100755 --- a/autotest/ogr/ogr_gpsbabel.py +++ b/autotest/ogr/ogr_gpsbabel.py @@ -35,20 +35,27 @@ from osgeo import gdal import pytest +def gpsbabel_binary_found(): + try: + ret = gdaltest.runexternal('gpsbabel -V') + return 'GPSBabel' in ret + except OSError: + return False + + pytestmark = [ pytest.mark.require_driver('GPSBabel'), - pytest.mark.require_driver('GPX') ] + pytest.mark.require_driver('GPX'), + pytest.mark.skipif(not gpsbabel_binary_found(), reason='GPSBabel utility not found') ] ############################################################################### @pytest.fixture(autouse=True, scope='module') def startup_and_cleanup(): - # Test if the gpsbabel is accessible - try: - ret = gdaltest.runexternal('gpsbabel -V') - except OSError: - ret = '' - if ret.find('GPSBabel') == -1: - pytest.skip('Cannot access GPSBabel utility') + # Check that the GPX driver has read support + with gdaltest.error_handler(): + if ogr.Open('data/gpx/test.gpx') is None: + assert 'Expat' in gdal.GetLastErrorMsg() + pytest.skip('GDAL build without Expat support') ############################################################################### # Test reading with explicit subdriver diff --git a/autotest/ogr/ogr_gpx.py b/autotest/ogr/ogr_gpx.py index a4edda9aa234..45dd65f4a3d2 100755 --- a/autotest/ogr/ogr_gpx.py +++ b/autotest/ogr/ogr_gpx.py @@ -39,13 +39,15 @@ pytestmark = pytest.mark.require_driver('GPX') - ############################################################################### @pytest.fixture(autouse=True, scope='module') def startup_and_cleanup(): - if ogr.Open('data/gpx/test.gpx') is None: - pytest.skip() + # Check that the GPX driver has read support + with gdaltest.error_handler(): + if ogr.Open('data/gpx/test.gpx') is None: + assert 'Expat' in gdal.GetLastErrorMsg() + pytest.skip('GDAL build without Expat support') yield