Skip to content
Permalink
Browse files

run python tests from build directory

  • Loading branch information
jef-n committed Jul 25, 2012
1 parent 269d32c commit fdefb5bffb45eedfa64d2a4ce638ddceddb355a1
Showing with 74 additions and 63 deletions.
  1. +11 −1 cmake/SIPMacros.cmake
  2. +35 −38 cmake/UsePythonTest.cmake
  3. +8 −6 src/core/qgsapplication.cpp
  4. +1 −1 src/gui/qgsmapcanvas.cpp
  5. +19 −17 tests/src/python/test_qgisapp.py
@@ -46,7 +46,7 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
SET(EXTRA_LINK_LIBRARIES ${ARGN})

STRING(REPLACE "." "/" _x ${MODULE_NAME})
GET_FILENAME_COMPONENT(_parent_module_path ${_x} PATH)
GET_FILENAME_COMPONENT(_parent_module_path ${_x} PATH)
GET_FILENAME_COMPONENT(_child_module_name ${_x} NAME)

GET_FILENAME_COMPONENT(_module_path ${MODULE_SIP} PATH)
@@ -127,6 +127,16 @@ MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ".pyd")
ENDIF (WIN32)

IF(WIN32)
GET_TARGET_PROPERTY(_target_location ${_logical_name} LOCATION)
GET_TARGET_PROPERTY(_runtime_output ${_logical_name} RUNTIME_OUTPUT_DIRECTORY)
ADD_CUSTOM_COMMAND(TARGET ${_logical_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Copying extension ${_child_module_name}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_target_location}" "${_runtime_output}/${_child_module_name}.pyd"
DEPENDS ${_logical_name}
)
ENDIF(WIN32)

INSTALL(TARGETS ${_logical_name} DESTINATION "${PYTHON_SITE_PACKAGES_DIR}/${_parent_module_path}")

ENDMACRO(ADD_SIP_PYTHON_MODULE)
@@ -1,5 +1,4 @@
# Add a python test from a python file
# One cannot simply do:
# 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})
@@ -26,44 +25,42 @@ 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)
IF(CMAKE_CONFIGURATION_TYPES)
# I cannot use CMAKE_CFG_INTDIR since it expand to "$(OutDir)"
IF(pyenv)
SET(pyenv "${pyenv};${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}")
ELSE(pyenv)
SET(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE})
#SET(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
#SET(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CONFIG_TYPE})
#SET(pyenv ${LIBRARY_OUTPUT_PATH}/\${CMAKE_CONFIG_TYPE})
ENDIF(pyenv)
ELSE(CMAKE_CONFIGURATION_TYPES)
IF(pyenv)
SET(pyenv ${pyenv}:${LIBRARY_OUTPUT_PATH})
ELSE(pyenv)
SET(pyenv ${LIBRARY_OUTPUT_PATH})
ENDIF(pyenv)
ENDIF(CMAKE_CONFIGURATION_TYPES)
STRING(REGEX REPLACE ";" " " wo_semicolumn "${ARGN}")

IF(WIN32)
STRING(REGEX REPLACE ":" " " wo_semicolon "${ARGN}")
ELSE(WIN32)
STRING(REGEX REPLACE ";" " " wo_semicolon "${ARGN}")
ENDIF(WIN32)

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake
"
SET(ENV{PYTHONPATH} ${pyenv}:\$ENV{PYTHONPATH})
SET(ENV{LD_LIBRARY_PATH} ${pyenv}:\$ENV{LD_LIBRARY_PATH})
MESSAGE(\"${pyenv}\")
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${loc} ${wo_semicolumn}
#WORKING_DIRECTORY @LIBRARY_OUTPUT_PATH@
RESULT_VARIABLE import_res
OUTPUT_VARIABLE import_output
ERROR_VARIABLE import_output
)
# Pass the output back to ctest
IF(import_output)
MESSAGE("\${import_output}")
ENDIF(import_output)
IF(import_res)
MESSAGE(SEND_ERROR "\${import_res}")
ENDIF(import_res)
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_semicolumn}
#WORKING_DIRECTORY @LIBRARY_OUTPUT_PATH@
RESULT_VARIABLE import_res
OUTPUT_VARIABLE import_output
ERROR_VARIABLE import_output
)
# Pass the output back to ctest
IF(import_output)
MESSAGE("\${import_output}")
ENDIF(import_output)
IF(import_res)
MESSAGE(SEND_ERROR "\${import_res}")
ENDIF(import_res)
"
)
ADD_TEST(${TESTNAME} ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake)
@@ -85,28 +85,30 @@ void QgsApplication::init( QString customConfigPath )
}
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );

// check if QGIS is run from build directory (not the install directory)
QDir appDir( applicationDirPath() );
QDir appDir( prefixPath );
#ifndef _MSC_VER
#define SOURCE_PATH "source_path.txt"
#else
#define SOURCE_PATH "../source_path.txt"
#endif
if ( appDir.exists( SOURCE_PATH ) )
{
QFile f( applicationDirPath() + "/" + SOURCE_PATH );
QFile f( prefixPath + "/" + SOURCE_PATH );
if ( f.open( QIODevice::ReadOnly ) )
{
ABISYM( mRunningFromBuildDir ) = true;
ABISYM( mBuildSourcePath ) = f.readAll();
#if _MSC_VER
QStringList elems = applicationDirPath().split( "/", QString::SkipEmptyParts );
QStringList elems = prefixPath.split( "/", QString::SkipEmptyParts );
ABISYM( mCfgIntDir ) = elems.last();
ABISYM( mBuildOutputPath ) = applicationDirPath() + "/../..";
ABISYM( mBuildOutputPath ) = prefixPath + "/../..";
#elif defined(Q_WS_MACX)
ABISYM( mBuildOutputPath ) = applicationDirPath();
ABISYM( mBuildOutputPath ) = prefixPath;
#else
ABISYM( mBuildOutputPath ) = applicationDirPath() + "/.."; // on linux
ABISYM( mBuildOutputPath ) = prefixPath + "/.."; // on linux
#endif
qDebug( "Running from build directory!" );
qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toAscii().data() );
@@ -158,7 +158,7 @@ QgsMapCanvas::~QgsMapCanvas()
it++;
}

delete mScene;
mScene->deleteLater(); // crashes in python tests on windows

delete mMapRenderer;
// mCanvasProperties auto-deleted via std::auto_ptr
@@ -1,25 +1,27 @@
import unittest
from utilities import (getQgisTestApp,
setCanvasCrs,
GEOCRS,
GOOGLECRS
)
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

class TestQGisApp(unittest.TestCase):
from utilities import getQgisTestApp

def testValidThemeName(self):
"""That can set the app to use a valid theme"""
QGISAPP.setThemeName('gis')
myExpectedResult = 'gis'
myResult = QGISAPP.themeName()
myMessage = ('Expected:\n%s\nGot:\n%s\n' %
(myExpectedResult, myResult))
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()

mySettings = QGISAPP.showSettings()
print mySettings
class TestQGisApp(unittest.TestCase):

assert myExpectedResult == myResult, myMessage
# Can this work at all?
# The theme resources are built into the executable and should only be
# available to plugins and not in test applications.
#
# def testValidThemeName(self):
# """That can set the app to use a valid theme"""
# QGISAPP.setThemeName('gis')
# myExpectedResult = 'gis'
# myResult = QGISAPP.themeName()
# myMessage = ('Expected:\n%s\nGot:\n%s\n' %
# (myExpectedResult, myResult))
#
# mySettings = QGISAPP.showSettings()
# print mySettings
#
# assert myExpectedResult == myResult, myMessage

def testInvalidThemeName(self):
"""That setting the app to use an invalid theme will fallback to 'default'"""

0 comments on commit fdefb5b

Please sign in to comment.
You can’t perform that action at this time.