Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Processing] fixup parameters test
- Broke into per class testcase
- Each method tries to test only one aspect of behavior
- Use unittest assertions for better error output
- Removed non-existant serialize functionality from tests
- Test BooleanParameter

Conflicts:
	python/plugins/processing/core/parameters.py
  • Loading branch information
michaelkirk authored and rldhont committed Dec 24, 2015
1 parent 8798c42 commit afcf567
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 104 deletions.
3 changes: 3 additions & 0 deletions ci/travis/linux/before_install.sh
Expand Up @@ -45,8 +45,11 @@ sudo apt-get install --force-yes --no-install-recommends --no-install-suggests \
python-qt4 \
python-qt4-dev \
python-qt4-sql \
python-qscintilla2 \
python-sip \
python-sip-dev \
python-psycopg2 \
python-numpy \
python-gdal \
spawn-fcgi \
txt2tags \
Expand Down
2 changes: 1 addition & 1 deletion ci/travis/linux/install.sh
Expand Up @@ -8,7 +8,7 @@ cmake --version
${CC} --version

cmake -DWITH_SERVER=ON \
-DWITH_STAGED_PLUGINS=OFF \
-DWITH_STAGED_PLUGINS=ON \
-DWITH_GRASS=ON \
-DSUPPRESS_QT_WARNINGS=ON \
-DENABLE_MODELTEST=ON \
Expand Down
3 changes: 3 additions & 0 deletions ci/travis/osx/before_install.sh
Expand Up @@ -16,3 +16,6 @@ brew ln libffi --force

mkdir -p /Users/travis/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/travis/Library/Python/2.7/lib/python/site-packages/homebrew.pth

# Needed for Processing
pip install psycopg2 numpy
2 changes: 1 addition & 1 deletion ci/travis/osx/install.sh
Expand Up @@ -3,7 +3,7 @@ cd build
#no PGTEST for OSX - can't get postgres to start with brew install
#no APIDOC for OSX - doxygen tests and warnings are covered by linux build
#no deprecated-declarations warnings... requires QGIS ported to Cocoa
cmake -DWITH_SERVER=ON -DWITH_STAGED_PLUGINS=OFF -DWITH_GRASS=OFF \
cmake -DWITH_SERVER=ON -DWITH_STAGED_PLUGINS=ON -DWITH_GRASS=OFF \
-DSUPPRESS_QT_WARNINGS=ON -DENABLE_MODELTEST=ON -DENABLE_PGTEST=OFF \
-DWITH_QWTPOLAR=OFF -DWITH_PYSPATIALITE=ON \
-DQWT_INCLUDE_DIR=/usr/local/opt/qwt/lib/qwt.framework/Headers/ \
Expand Down
70 changes: 27 additions & 43 deletions cmake/UsePythonTest.cmake
@@ -1,16 +1,11 @@
# Add a python test from a python file # One cannot simply do:
# SET(ENV{PYTHONPATH} ${LIBRARY_OUTPUT_PATH})
# SET(my_test "from test_mymodule import *\;test_mymodule()")
# ADD_TEST(PYTHON-TEST-MYMODULE python -c ${my_test})
# Since cmake is only transmitting the ADD_TEST line to ctest thus you are loosing
# the env var. The only way to store the env var is to physically write in the cmake script
# whatever PYTHONPATH you want and then add the test as 'cmake -P python_test.cmake'
# Add a python test from a python file
#
# Usage:
# SET_SOURCE_FILES_PROPERTIES(test.py PROPERTIES PYTHONPATH
# "${LIBRARY_OUTPUT_PATH}:${VTK_DIR}")
# ADD_PYTHON_TEST(PYTHON-TEST test.py)
#
# Optionally pass environment variables to your test
# ADD_PYTHON_TEST(PYTHON-TEST test.py FOO="bar" BAZ="quux")
#
# Copyright (c) 2006-2010 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Redistribution and use is allowed according to the terms of the New
Expand All @@ -24,45 +19,34 @@ MARK_AS_ADVANCED(PYTHON_EXECUTABLE)

MACRO(ADD_PYTHON_TEST TESTNAME FILENAME)
GET_SOURCE_FILE_PROPERTY(loc ${FILENAME} LOCATION)
GET_SOURCE_FILE_PROPERTY(pyenv ${FILENAME} PYTHONPATH)
SET(EXTRA_ENVIRONMENT ${ARGN})

IF(CMAKE_CONFIGURATION_TYPES)
ADD_TEST(NAME ${TESTNAME} COMMAND ${PYTHON_EXECUTABLE} ${loc} -D CMAKE_BUILD_TYPE=$<CONFIGURATION>)
ELSE(CMAKE_CONFIGURATION_TYPES)
ADD_TEST(NAME ${TESTNAME} COMMAND ${PYTHON_EXECUTABLE} ${loc})
ENDIF(CMAKE_CONFIGURATION_TYPES)

SET(UNIX_TEST_PYTHONPATH "${QGIS_OUTPUT_DIRECTORY}/python:${QGIS_OUTPUT_DIRECTORY}/python/plugins:${CMAKE_SOURCE_DIR}/tests/src/python:$ENV{PYTHONPATH}")
IF(WIN32)
STRING(REGEX REPLACE ":" " " wo_semicolon "${ARGN}")
# Separate Windows PATHs with semicolons
STRING(REGEX REPLACE ":" "\\\;" TEST_PYTHONPATH ${UNIX_TEST_PYTHONPATH})
SET(TEST_QGIS_PREFIX_PATH "${QGIS_OUTPUT_DIRECTORY}/bin/${CMAKE_BUILD_TYPE}")
SET(TEST_PATH "${QGIS_OUTPUT_DIRECTORY}/bin/${CMAKE_BUILD_TYPE};$ENV{PATH}")
SET(ENVIRONMENT_VARS "PYTHONPATH=${TEST_PYTHONPATH}" "QGIS_PREFIX_PATH=${TEST_QGIS_PREFIX_PATH}" "PATH=${TEST_PATH}")
ELSE(WIN32)
STRING(REGEX REPLACE ";" " " wo_semicolon "${ARGN}")
SET(TEST_PYTHONPATH ${UNIX_TEST_PYTHONPATH})
SET(TEST_QGIS_PREFIX_PATH "${QGIS_OUTPUT_DIRECTORY}")
SET(TEST_LD_LIBRARY_PATH "${QGIS_OUTPUT_DIRECTORY}/lib:$ENV{LD_LIBRARY_PATH}")
SET(ENVIRONMENT_VARS "PYTHONPATH=${TEST_PYTHONPATH}" "QGIS_PREFIX_PATH=${TEST_QGIS_PREFIX_PATH}" "LD_LIBRARY_PATH=${TEST_LD_LIBRARY_PATH}")
ENDIF(WIN32)
SET(TEST_ENVIRONMENT_VARS ${ENVIRONMENT_VARS} ${EXTRA_ENVIRONMENT})

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake
"
IF(WIN32)
SET(ENV{QGIS_PREFIX_PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin/\${CMAKE_BUILD_TYPE}\")
SET(ENV{PATH} \"${QGIS_OUTPUT_DIRECTORY}/bin/\${CMAKE_BUILD_TYPE};\$ENV{PATH}\")
SET(ENV{PYTHONPATH} \"${QGIS_OUTPUT_DIRECTORY}/python/;\$ENV{PYTHONPATH}\")
MESSAGE(\"PATH:\$ENV{PATH}\")
ELSE(WIN32)
SET(ENV{QGIS_PREFIX_PATH} \"${QGIS_OUTPUT_DIRECTORY}\")
SET(ENV{LD_LIBRARY_PATH} \"${pyenv}:${QGIS_OUTPUT_DIRECTORY}/lib:\$ENV{LD_LIBRARY_PATH}\")
SET(ENV{PYTHONPATH} \"${QGIS_OUTPUT_DIRECTORY}/python/:\$ENV{PYTHONPATH}\")
MESSAGE(\"LD_LIBRARY_PATH:\$ENV{LD_LIBRARY_PATH}\")
ENDIF(WIN32)
MESSAGE(\"PYTHONPATH:\$ENV{PYTHONPATH}\")
MESSAGE(STATUS \"Running ${PYTHON_EXECUTABLE} ${loc} ${wo_semicolon}\")
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${loc} ${wo_semicolon}
RESULT_VARIABLE import_res
)
# Pass the output back to ctest
IF(import_res)
MESSAGE(FATAL_ERROR \"Test failed: \${import_res}\")
ENDIF(import_res)
"
)
IF(CMAKE_CONFIGURATION_TYPES)
ADD_TEST(NAME ${TESTNAME} COMMAND ${CMAKE_COMMAND} -D CMAKE_BUILD_TYPE=$<CONFIGURATION> -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake)
ELSE(CMAKE_CONFIGURATION_TYPES)
ADD_TEST(NAME ${TESTNAME} COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake)
ENDIF(CMAKE_CONFIGURATION_TYPES)
SET_PROPERTY(TEST ${TESTNAME} PROPERTY ENVIRONMENT ${TEST_ENVIRONMENT_VARS})
# For Debug
#FOREACH(arg ${TEST_ENVIRONMENT_VARS})
# MESSAGE("Test ENV: ${arg}")
#ENDFOREACH()
ENDMACRO(ADD_PYTHON_TEST)

# Byte compile recursively a directory (DIRNAME)
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/CMakeLists.txt
Expand Up @@ -7,8 +7,10 @@ ADD_SUBDIRECTORY(images)
ADD_SUBDIRECTORY(modeler)
ADD_SUBDIRECTORY(script)
ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(ui)
IF (ENABLE_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF (ENABLE_TESTS)

FILE(GLOB OTHER_FILES metadata.txt)
FILE(GLOB PY_FILES *.py)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -61,7 +61,7 @@ def __init__(self):

self.modeComboBox.clear()
self.modeComboBox.addItems([self.tr('Simplified interface'),
self.tr('Advanced interface')])
self.tr('Advanced interface')])
settings = QSettings()
if not settings.contains(self.USE_CATEGORIES):
settings.setValue(self.USE_CATEGORIES, True)
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/tests/CMakeLists.txt
Expand Up @@ -3,3 +3,7 @@ FILE(GLOB TEST_DATA_FILES data/*)

PLUGIN_INSTALL(processing tests ${PY_FILES})
PLUGIN_INSTALL(processing tests/data ${TEST_DATA_FILES})

INCLUDE(UsePythonTest)

ADD_PYTHON_TEST(ProcessingParametersTest ParametersTest.py)

0 comments on commit afcf567

Please sign in to comment.