Permalink
Browse files

Merge pull request #5657 from geographika/python-test-fixes

Add test suite to Python Wheel Builds
  • Loading branch information...
geographika committed Sep 8, 2018
2 parents efb012a + 371d465 commit 265c7e0b31168551d4d289a679ceda56f4a2a81a
Showing with 102 additions and 59 deletions.
  1. +1 −9 appveyor.yml
  2. +63 −18 mapscript/python/CMakeLists.txt
  3. +20 −19 mapscript/python/README.rst
  4. +3 −1 mapscript/python/requirements-dev.txt
  5. +5 −2 mapscript/python/setup.py.in
  6. 0 mapscript/python/tests/cases/{classtest.py → class_test.py}
  7. 0 mapscript/python/tests/cases/{clonetest.py → clone_test.py}
  8. 0 mapscript/python/tests/cases/{colortest.py → colort_est.py}
  9. 0 mapscript/python/tests/cases/{fonttest.py → font_test.py}
  10. +1 −2 mapscript/python/tests/cases/{hashtest.py → hash_test.py}
  11. 0 mapscript/python/tests/cases/{imagetest.py → image_test.py}
  12. 0 mapscript/python/tests/cases/{labeltest.py → label_test.py}
  13. 0 mapscript/python/tests/cases/{layertest.py → layer_test.py}
  14. 0 mapscript/python/tests/cases/{linetest.py → line_test.py}
  15. 0 mapscript/python/tests/cases/{maptest.py → map_test.py}
  16. 0 mapscript/python/tests/cases/{outputformattest.py → outputformat_test.py}
  17. 0 mapscript/python/tests/cases/{owstest.py → ows_test.py}
  18. 0 mapscript/python/tests/cases/{pointtest.py → point_test.py}
  19. +0 −2 mapscript/python/tests/cases/pytest.ini
  20. 0 mapscript/python/tests/cases/{recttest.py → rect_test.py}
  21. 0 mapscript/python/tests/cases/{resultcachetest.py → resultcache_test.py}
  22. 0 mapscript/python/tests/cases/{shapetest.py → shape_test.py}
  23. 0 mapscript/python/tests/cases/{shapefiletest.py → shapefile_test.py}
  24. 0 mapscript/python/tests/cases/{styletest.py → style_test.py}
  25. 0 mapscript/python/tests/cases/{symboltest.py → symbol_test.py}
  26. 0 mapscript/python/tests/cases/{symbolsettest.py → symbolset_test.py}
  27. +9 −6 mapscript/python/tests/cases/testing.py
  28. 0 mapscript/python/tests/cases/{zoomtest.py → zoom_test.py}
View
@@ -42,17 +42,9 @@ build_script:
- cmake -G "%VS_FULL%" .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%SDK_PREFIX% -DFREETYPE_INCLUDE_DIR_freetype2=%SDK_INC%/freetype -DFREETYPE_INCLUDE_DIR_ft2build=%SDK_INC%/freetype -DFREETYPE_LIBRARY=%SDK_LIB%/freetype.lib -DZLIB_INCLUDE_DIR=%SDK_INC% -DZLIB_LIBRARY=%SDK_LIB%/zlib.lib -DPNG_PNG_INCLUDE_DIR=%SDK_INC% -DPNG_LIBRARY=%SDK_LIB%/libpng.lib -DPNG_LIBRARIES=%SDK_LIB%/libpng.lib -DJPEG_INCLUDE_DIR=%SDK_INC% -DJPEG_LIBRARY=%SDK_LIB%/libjpeg.lib -DWITH_PROJ=1 -DPROJ_INCLUDE_DIR=%SDK_INC% -DPROJ_LIBRARY=%SDK_LIB%/proj_i.lib -DFRIBIDI_INCLUDE_DIR=%SDK_INC% -DFRIBIDI_LIBRARY=%SDK_LIB%/fribidi.lib -DHARFBUZZ_INCLUDE_DIR=%SDK_INC%/harfbuzz -DHARFBUZZ_LIBRARY=%SDK_LIB%/harfbuzz.lib -DICONV_INCLUDE_DIR=%SDK_INC% -DICONV_LIBRARY=%SDK_LIB%/iconv.lib -DICONV_DLL=%SDK_BIN%/iconv.dll -DCAIRO_INCLUDE_DIR=%SDK_INC% -DCAIRO_LIBRARY=%SDK_LIB%/cairo.lib -DFCGI_INCLUDE_DIR=%SDK_INC% -DFCGI_LIBRARY=%SDK_LIB%/libfcgi.lib -DGEOS_INCLUDE_DIR=%SDK_INC% -DGEOS_LIBRARY=%SDK_LIB%/geos_c.lib -DPOSTGRESQL_INCLUDE_DIR=%SDK_INC% -DPOSTGRESQL_LIBRARY=%SDK_LIB%/libpqdll.lib -DGDAL_INCLUDE_DIR=%SDK_INC% -DGDAL_LIBRARY=%SDK_LIB%/gdal_i.lib -DLIBXML2_INCLUDE_DIR=%SDK_INC%/libxml -DLIBXML2_LIBRARIES=%SDK_LIB%/libxml2.lib -DGIF_INCLUDE_DIR=%SDK_INC% -DGIF_LIBRARY=%SDK_LIB%/giflib.lib -DWITH_CURL=1 -DCURL_INCLUDE_DIR=%SDK_INC% -DCURL_LIBRARY=%SDK_LIB%/libcurl_imp.lib -DMS_EXTERNAL_LIBS=wsock32.lib -DWITH_SOS=1 -DWITH_CLIENT_WFS=1 -DWITH_CLIENT_WMS=1 -DSVG_INCLUDE_DIR=%SDK_INC% -DSVG_LIBRARY=%SDK_LIB%/libsvg.lib -DSVGCAIRO_INCLUDE_DIR=%SDK_INC% -DSVGCAIRO_LIBRARY=%SDK_LIB%/libsvg-cairo.lib -DWITH_SVGCAIRO=1 -DREGEX_DIR=%REGEX_DIR% -DWITH_POINT_Z_M=1 -DWITH_KML=1 -DWITH_THREAD_SAFETY=1 -DSWIG_EXECUTABLE=%SWIG_EXECUTABLE% -DWITH_PYTHON=1 -DPYTHON_EXECUTABLE=%PYTHON_EXECUTABLE% -DWITH_CSHARP=1 -DWITH_PROTOBUFC=0
- cmake --build . --config Release
before_test:
- "%PYTHON_EXECUTABLE% -m pip install --upgrade pip"
- cd %BUILD_FOLDER%/mapscript/python
- "%PYTHON_EXECUTABLE% -m pip install -r requirements-dev.txt"
test_script:
- set PATH=%BUILD_FOLDER%/build/Release;%BUILD_FOLDER%/sdk/%SDK%/bin;%PATH%
- set PROJ_LIB=%BUILD_FOLDER%/sdk/%SDK%/bin/proj/SHARE
- set PYTHONPATH=%BUILD_FOLDER%/build/mapscript/python/Release;%BUILD_FOLDER%/build/mapscript/python
- cd %BUILD_FOLDER%
- set TESTS_FOLDER=%BUILD_FOLDER%/mapscript/python/tests/cases
- "%PYTHON_EXECUTABLE% -m pytest --ignore=%TESTS_FOLDER%/fonttest.py --ignore=%TESTS_FOLDER%/hashtest.py --ignore=%TESTS_FOLDER%/pgtest.py --ignore=%TESTS_FOLDER%/threadtest.py %TESTS_FOLDER%"
- cmake --build . --target pythonmapscript-wheel --config Release
deploy: off
@@ -21,22 +21,22 @@ find_library(PYTHON_LIBRARIES
#if that failed, fall back to the default cmake method of finding python dev files
if(NOT PYTHON_INCLUDE_PATH OR NOT PYTHON_LIBRARIES)
find_package(PythonLibs)
endif(NOT PYTHON_INCLUDE_PATH OR NOT PYTHON_LIBRARIES)
endif()
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${PROJECT_SOURCE_DIR}/mapscript/swiginc)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/)
include_directories(${PROJECT_SOURCE_DIR}/mapscript/python)
if (${PYTHON_VERSION_MAJOR} GREATER 2)
if (${PYTHON_VERSION_MAJOR} VERSION_GREATER 2)
set_property(SOURCE ../mapscript.i PROPERTY SWIG_FLAGS "-py3")
endif (${PYTHON_VERSION_MAJOR} GREATER 2)
endif ()
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 3.7)
swig_add_library(pythonmapscript TYPE MODULE LANGUAGE python SOURCES ../mapscript.i)
else (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
else ()
swig_add_module(pythonmapscript python ../mapscript.i)
endif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.7)
endif ()
swig_link_libraries(pythonmapscript ${PYTHON_LIBRARIES} ${MAPSERVER_LIBMAPSERVER})
@@ -50,35 +50,80 @@ set(SETUP_PY_TEMP "${CMAKE_CURRENT_BINARY_DIR}/setup.py.temp")
configure_file(${SETUP_PY_IN} ${SETUP_PY_TEMP} @ONLY)
file(READ ${SETUP_PY_TEMP} SETUP_CONTENT)
# each target (e.g. Debug, Release etc.) will have a copy of setup.py
file(GENERATE OUTPUT $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/setup.py INPUT ${SETUP_PY_TEMP})
set(BUILD_TIMESTAMP "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
set(TESTS_FOLDER ${PROJECT_SOURCE_DIR}/mapscript/python/tests/cases)
add_custom_target(pythonmapscript-wheel DEPENDS ${SWIG_MODULE_pythonmapscript_REAL_NAME} )
if(MSVC)
set(OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
else()
# for non-Windows builds there are no build type subfolders (e.g. Release, Debug etc.)
set(OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
endif()
# copy all Python files to the output folder following build, and create a wheel
if (WIN32)
set(PYTHON_MAPSCRIPT_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
if(WIN32)
set(PYTHON_SCRIPTS ${OUTPUT_FOLDER}/mapscriptvenv/Scripts)
set(PYTHON_VENV_SCRIPTS ${OUTPUT_FOLDER}/mapscriptvenv/Scripts)
else()
set(PYTHON_MAPSCRIPT_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
set(PYTHON_SCRIPTS ${OUTPUT_FOLDER}/mapscriptvenv/Scripts)
set(PYTHON_VENV_SCRIPTS ${OUTPUT_FOLDER}/mapscriptvenv/bin)
endif()
add_custom_target(
pythonmapscript-wheel
DEPENDS mapscripttests.stamp
)
add_custom_command(
DEPENDS ${SWIG_MODULE_pythonmapscript_REAL_NAME}
OUTPUT mapscriptvenv.stamp
WORKING_DIRECTORY ${OUTPUT_FOLDER}
COMMENT "Creating a Python virtual environment"
COMMAND ${PYTHON_EXECUTABLE} -m pip install virtualenv
COMMAND ${PYTHON_EXECUTABLE} -m virtualenv mapscriptvenv
)
add_custom_command(
DEPENDS mapscriptvenv.stamp
OUTPUT mapscriptvenvpop.stamp
WORKING_DIRECTORY ${OUTPUT_FOLDER}
COMMENT "Installing the required packages into the virtual environment"
COMMAND ${PYTHON_VENV_SCRIPTS}/python -m pip install pip --upgrade
COMMAND ${PYTHON_VENV_SCRIPTS}/pip install -r ${PROJECT_SOURCE_DIR}/mapscript/python/requirements-dev.txt
)
add_custom_command(
TARGET pythonmapscript-wheel POST_BUILD
WORKING_DIRECTORY ${PYTHON_MAPSCRIPT_WORKING_DIRECTORY}
COMMAND ${PYTHON_EXECUTABLE} -m pip install --user -r ${PROJECT_SOURCE_DIR}/mapscript/python/requirements-dev.txt
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/mapscript/python/mapscript" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript
DEPENDS mapscriptvenvpop.stamp
OUTPUT mapscriptwheel.stamp
WORKING_DIRECTORY ${OUTPUT_FOLDER}
COMMENT "Building the mapscript Python wheel"
COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/mapscript/python/mapscript/__init__.py" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/__init__.py
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/mapscript.py" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/mapscript.py
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${SWIG_MODULE_pythonmapscript_REAL_NAME}>" "$<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/$<TARGET_FILE_NAME:${SWIG_MODULE_pythonmapscript_REAL_NAME}>"
COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/mapscript/python/README.rst" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/README.rst
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/mapscript/python/tests/cases" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/tests
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/tests" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/tests/data
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/mapscript/python/examples" $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/examples
COMMAND ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index --find-links=${CMAKE_CURRENT_BINARY_DIR}/dist mapscript
COMMAND ${PYTHON_EXECUTABLE} -m pytest --ignore=${TESTS_FOLDER}/fonttest.py --ignore=${TESTS_FOLDER}/hashtest.py --ignore=${TESTS_FOLDER}/pgtest.py --ignore=${TESTS_FOLDER}/threadtest.py ${TESTS_FOLDER}/)
COMMAND ${PYTHON_VENV_SCRIPTS}/python setup.py bdist_wheel
)
add_custom_command(
DEPENDS mapscriptwheel.stamp
OUTPUT mapscripttests.stamp
COMMENT "Installing the Python wheel and testing it in the virtual environment"
COMMAND ${PYTHON_VENV_SCRIPTS}/pip install --no-index --find-links=${OUTPUT_FOLDER}/dist mapscript
COMMAND ${PYTHON_VENV_SCRIPTS}/pytest --pyargs mapscript.tests
)
set(mapscript_files $<TARGET_FILE:${SWIG_MODULE_pythonmapscript_REAL_NAME}> $<TARGET_FILE_DIR:${SWIG_MODULE_pythonmapscript_REAL_NAME}>/mapscript/mapscript.py)
install(FILES ${mapscript_files} DESTINATION ${PYTHON_SITE_PACKAGES})
message(STATUS "CMake version: ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Python MapScript output directory: ${OUTPUT_FOLDER}")
message(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
message(STATUS "Python site packages: ${PYTHON_SITE_PACKAGES}")
@@ -1,8 +1,8 @@
Python MapScript for MapServer 7.2 README
=========================================
Python MapScript for MapServer 7.2.1 README
===========================================
:Author: MapServer Team
:Last Updated: 2018-08-21
:Last Updated: 2018-09-04
Introduction
------------
@@ -45,14 +45,18 @@ Linux wheels are also planned, using the `manylinux <https://github.com/pypa/man
No source distributions will be provided on PyPI - to build from source requires the full MapServer source code,
in which case it is easiest to take a copy of the full MapServer project and run the CMake process detailed below.
The wheels also contain a full test suite and sample data that can be run to check that the installed MapServer is
running correctly.
..
py3 SWIG flag adds type annotations
Installation
------------
To use mapscript you will need to add the MapServer binaries to your system path.
On Windows you can use the following, replacing ``C:\MapServer\bin`` with the location of your MapServer binaries.
On Windows you can use the following, replacing ``C:\MapServer\bin`` with the location of your MapServer binaries
(see also `MapServer Versions`_).
.. code-block::
@@ -81,12 +85,6 @@ If you already have mapscript installed and wish to upgrade it to a newer versio
pip install mapscript --upgrade
Add your MapSever binaries folder to your system path (see `MapServer Versions`_):
.. code-block::
SET PATH=C:\MapServer\bin;%PATH%
Now you should be able to import mapscript:
.. code-block:: python
@@ -150,21 +148,25 @@ The build process works as follows.
+ CMake then uses the appropriate compiler on the system to compile the ``mapscriptPYTHON_wrap.c`` file into a Python binary module -
``_mapscript.pyd`` file on Windows, and a ``_mapscript.so`` file on Windows.
``CMakeLists.txt`` is configured so that all files required to make a Python wheel are copied into the output build folder. The wheel can then be built
using the following command:
``CMakeLists.txt`` is configured with a ``pythonmapscript-wheel`` target that copies all the required files to the output build folder where they are then packaged
into a Python wheel. The wheel can be built using the following command:
.. code-block:: bat
cmake --build . --target pythonmapscript-wheel
The ``pythonmapscript-wheel`` target runs the following commands:
The ``pythonmapscript-wheel`` target creates a virtual environment, creates the Python wheel, installs it to the virtual environment and finally runs the test
suite. This process runs commands similar to the following:
.. code-block:: bat
python -m pip install virtualenv
virtualenv mapscriptvenv
python -m pip install --upgrade pip
pip install wheel
cd C:\Projects\MapServer\build\mapscript\python
pip install -r requirements-dev.txt
python setup.py bdist_wheel
pip install --no-index --find-links=dist mapscript
python -m pytest --pyargs mapscript.tests
SWIG can also be run manually, without using CMake. This may allow further optimizations and control on the output.
@@ -185,20 +187,19 @@ SWIG has several command line options to control the output, examples of which a
Testing
-------
Once the mapscript module has been built there is a test suite to check the output. It is recommended
The mapscript module includes a test suite and a small sample dataset to check the output and MapServer installation. It is recommended
`pytest <https://docs.pytest.org/en/latest/>`_ is used to run the tests. This can be installed using:
.. code-block:: bat
pip install pytest
Change the directory to the mapscript output build folder and run the command below. Some tests are currently excluded, these will
be fixed for upcoming releases. It is also planned to include the test suite in the Python wheels to allow easy testing of a
mapscript installation.
be fixed for upcoming releases.
.. code-block:: bat
python -m pytest --ignore=tests/cases/fonttest.py --ignore=tests/cases/hashtest.py --ignore=tests/cases/pgtest.py --ignore=tests/cases/threadtest.py tests/cases
pytest --pyargs mapscript.tests
Credits
-------
@@ -1,2 +1,4 @@
pytest
pillow
pillow
wheel>=0.31.1
setuptools>=40.2.0
@@ -40,6 +40,9 @@ setup(
url="http://www.mapserver.org",
version="@MapServer_VERSION_MAJOR@.@MapServer_VERSION_MINOR@",
packages=find_packages(),
package_data={'mapscript': ['$<TARGET_FILE_NAME:@SWIG_MODULE_pythonmapscript_REAL_NAME@>']},
distclass=BinaryDistribution
package_data={
# list the files to include starting with the most deeply nested folder or they are overwritten
'mapscript': ['tests/data/vera/*.*', 'tests/data/*.*', '$<TARGET_FILE_NAME:@SWIG_MODULE_pythonmapscript_REAL_NAME@>']
},
distclass=BinaryDistribution
)
@@ -129,8 +129,7 @@ def tearDown(self):
def testConstructor(self):
table = mapscript.hashTableObj()
tabletype = type(table)
assert str(tabletype) == "<class 'mapscript.hashTableObj'>", tabletype
assert table.__class__.__name__== "hashTableObj", table
# ==============================================================================

This file was deleted.

Oops, something went wrong.
@@ -41,22 +41,25 @@
import sys
import distutils.util
import unittest
import tempfile
# define the path to mapserver test data
test_path = os.path.abspath(os.path.join(__file__ ,"../../../../.."))
TESTS_PATH = os.path.join(test_path, "tests")
TESTS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__ ),"data"))
# TESTS_PATH = os.path.join(test_path, "tests")
TESTMAPFILE = os.path.join(TESTS_PATH, 'test.map')
XMARKS_IMAGE = os.path.join(TESTS_PATH, 'xmarks.png')
HOME_IMAGE = os.path.join(TESTS_PATH, 'home.png')
TEST_IMAGE = os.path.join(TESTS_PATH, 'test.png')
INCOMING = '/tmp/'
INCOMING = tempfile.mkdtemp(prefix="mapscript")
# INCOMING = '/tmp/'
# Put local build directory on head of python path
platformdir = '-'.join((distutils.util.get_platform(),
'.'.join(map(str, sys.version_info[0:2]))))
sys.path.insert(0, os.path.join('../../build', 'lib.' + platformdir))
#platformdir = '-'.join((distutils.util.get_platform(),
# '.'.join(map(str, sys.version_info[0:2]))))
#sys.path.insert(0, os.path.join('../../build', 'lib.' + platformdir))
# import mapscript from the local build directory
import mapscript

0 comments on commit 265c7e0

Please sign in to comment.