From 5a6f8e88179d1d5c1f78a832842e6f62ffd432eb Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 4 Feb 2020 15:08:40 +0100 Subject: [PATCH] msautotest: add mspython in subdirectories explored by pytest, and skip properly mspython tests if mapscript not available --- msautotest/gdal/run_test.py | 3 +-- msautotest/misc/run_test.py | 3 +-- msautotest/mspython/test_bug_check.py | 10 ++++++++-- msautotest/mspython/test_mapio.py | 10 +++++++++- msautotest/mspython/test_ogr_query.py | 9 ++++++++- msautotest/mspython/test_rq.py | 10 +++++++++- msautotest/mspython/test_wkt.py | 9 ++++++++- msautotest/mspython/test_xmp.py | 9 ++++++++- msautotest/pymod/mstestlib.py | 23 +++++++++++++++++++++++ msautotest/pytest.ini | 2 +- msautotest/query/run_test.py | 3 +-- msautotest/renderers/run_test.py | 3 +-- msautotest/sld/run_test.py | 3 +-- msautotest/wxs/run_test.py | 3 +-- 14 files changed, 80 insertions(+), 20 deletions(-) diff --git a/msautotest/gdal/run_test.py b/msautotest/gdal/run_test.py index 9656ce4477..ee65170a60 100755 --- a/msautotest/gdal/run_test.py +++ b/msautotest/gdal/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main()) diff --git a/msautotest/misc/run_test.py b/msautotest/misc/run_test.py index 9656ce4477..ee65170a60 100755 --- a/msautotest/misc/run_test.py +++ b/msautotest/misc/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main()) diff --git a/msautotest/mspython/test_bug_check.py b/msautotest/mspython/test_bug_check.py index 757a9d07c4..582b2c8819 100755 --- a/msautotest/mspython/test_bug_check.py +++ b/msautotest/mspython/test_bug_check.py @@ -35,8 +35,14 @@ import pmstestlib -import mapscript - +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") def get_relpath_to_this(filename): return os.path.join(os.path.dirname(__file__), filename) diff --git a/msautotest/mspython/test_mapio.py b/msautotest/mspython/test_mapio.py index 7cc8608975..4a81bfc91d 100755 --- a/msautotest/mspython/test_mapio.py +++ b/msautotest/mspython/test_mapio.py @@ -31,7 +31,15 @@ import os import pytest -import mapscript + +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") def get_relpath_to_this(filename): diff --git a/msautotest/mspython/test_ogr_query.py b/msautotest/mspython/test_ogr_query.py index 027169dd1f..0c2aaae5b3 100755 --- a/msautotest/mspython/test_ogr_query.py +++ b/msautotest/mspython/test_ogr_query.py @@ -36,7 +36,14 @@ import pmstestlib -import mapscript +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") ############################################################################### # Dump query result set ... used when debugging this test script. diff --git a/msautotest/mspython/test_rq.py b/msautotest/mspython/test_rq.py index a04200a5d2..679d64efd5 100755 --- a/msautotest/mspython/test_rq.py +++ b/msautotest/mspython/test_rq.py @@ -34,8 +34,16 @@ import math import pmstestlib +import pytest -import mapscript +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") ############################################################################### # Dump query result set ... used when debugging this test script. diff --git a/msautotest/mspython/test_wkt.py b/msautotest/mspython/test_wkt.py index e833661575..e6e3e991a6 100755 --- a/msautotest/mspython/test_wkt.py +++ b/msautotest/mspython/test_wkt.py @@ -37,7 +37,14 @@ import pytest -import mapscript +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") ############################################################################### # Test simple geometries that should convert back to same thing - OGR only. diff --git a/msautotest/mspython/test_xmp.py b/msautotest/mspython/test_xmp.py index 595bc599db..b756fcd765 100755 --- a/msautotest/mspython/test_xmp.py +++ b/msautotest/mspython/test_xmp.py @@ -32,7 +32,14 @@ import os import pytest -import mapscript +mapscript_available = False +try: + import mapscript + mapscript_available = True +except ImportError: + pass + +pytestmark = pytest.mark.skipif(not mapscript_available, reason="mapscript not available") def get_relpath_to_this(filename): diff --git a/msautotest/pymod/mstestlib.py b/msautotest/pymod/mstestlib.py index 33bf1a991d..84a91a8c02 100644 --- a/msautotest/pymod/mstestlib.py +++ b/msautotest/pymod/mstestlib.py @@ -726,3 +726,26 @@ def run_pytest(map, out_file, command, extra_args): ret, msg = _run(map, out_file, command, extra_args) assert ret, msg + +############################################################################### + + +def pytest_main(): + maps = [] + new_argv = [] + help = False + for arg in sys.argv: + if arg.endswith('.map'): + maps.append(arg[0:-4]) + else: + if arg == '--help': + help = True + new_argv.append(arg) + sys.argv = new_argv + if maps: + sys.argv.append('-k') + sys.argv.append(' or '.join(maps)) + ret = pytest.main() + if help: + print('\nMapServer note: you can also specify one or several .map filenames') + return ret diff --git a/msautotest/pytest.ini b/msautotest/pytest.ini index cba0f0c13c..8085d43173 100644 --- a/msautotest/pytest.ini +++ b/msautotest/pytest.ini @@ -1,4 +1,4 @@ [pytest] python_files = *.py -testpaths = misc gdal query renderers wxs sld +testpaths = misc gdal query renderers wxs sld mspython diff --git a/msautotest/query/run_test.py b/msautotest/query/run_test.py index 4037d9326f..7d572d0cb6 100755 --- a/msautotest/query/run_test.py +++ b/msautotest/query/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main()) diff --git a/msautotest/renderers/run_test.py b/msautotest/renderers/run_test.py index 9656ce4477..ee65170a60 100755 --- a/msautotest/renderers/run_test.py +++ b/msautotest/renderers/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main()) diff --git a/msautotest/sld/run_test.py b/msautotest/sld/run_test.py index 9656ce4477..ee65170a60 100755 --- a/msautotest/sld/run_test.py +++ b/msautotest/sld/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main()) diff --git a/msautotest/wxs/run_test.py b/msautotest/wxs/run_test.py index 9656ce4477..ee65170a60 100755 --- a/msautotest/wxs/run_test.py +++ b/msautotest/wxs/run_test.py @@ -45,5 +45,4 @@ def test(map, out_file, command, extra_args): # main() if __name__ == '__main__': - sys.argv[0] = 'run_test.py' - sys.exit(pytest.main()) + sys.exit(mstestlib.pytest_main())