Skip to content
Permalink
Browse files
Migrate provider test to python 3
  • Loading branch information
m-kuhn committed May 13, 2016
1 parent 25f2e63 commit 7dfc69657ff275a7bed0b152c19b99c7432c4977
@@ -102,6 +102,8 @@ MACRO(GENERATE_SIP_PYTHON_MODULE_CODE MODULE_NAME MODULE_SIP CPP_FILES)
DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
)

ADD_CUSTOM_TARGET(generate_sip_${MODULE_NAME}_cpp_files DEPENDS ${_sip_output_files})

SET(CPP_FILES ${sip_output_files})
ENDMACRO(GENERATE_SIP_PYTHON_MODULE_CODE)

@@ -70,7 +70,9 @@ ADD_SUBDIRECTORY(PyQt)
ADD_SUBDIRECTORY(pyplugin_installer)
ADD_SUBDIRECTORY(ext-libs)
ADD_SUBDIRECTORY(testing)
ADD_SUBDIRECTORY(sip_helpers)
IF (PYQT5_VERSION_NUM)
ADD_SUBDIRECTORY(sip_helpers)
ENDIF (PYQT5_VERSION_NUM)

IF(POLICY CMP0040)
CMAKE_POLICY (POP) # see PUSH above
@@ -160,12 +162,20 @@ IF(NOT PYQT4_VERSION_NUM LESS 264453) # 0x040905
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} QVECTORINT_CONVERSION)
ENDIF(NOT PYQT4_VERSION_NUM LESS 264453)

IF (NOT PYQT5_VERSION_NUM)
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} CHIMERA_NULL_VARIANT_CONVERSION)
ENDIF (NOT PYQT5_VERSION_NUM)

# core module
FILE(GLOB_RECURSE sip_files_core core/*.sip)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core})
SET(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -o -a ${CMAKE_BINARY_DIR}/python/qgis.core.api)
GENERATE_SIP_PYTHON_MODULE_CODE(qgis._core core/core.sip cpp_files)
BUILD_SIP_PYTHON_MODULE(qgis._core core/core.sip ${cpp_files} $<TARGET_OBJECTS:qgis_sip_helpers> qgis_core)
IF (PYQT5_VERSION_NUM)
BUILD_SIP_PYTHON_MODULE(qgis._core core/core.sip ${cpp_files} $<TARGET_OBJECTS:qgis_sip_helpers> qgis_core)
ELSE (PYQT5_VERSION_NUM)
BUILD_SIP_PYTHON_MODULE(qgis._core core/core.sip ${cpp_files} "" qgis_core)
ENDIF (PYQT5_VERSION_NUM)
SET(SIP_CORE_CPP_FILES ${cpp_files})

# additional gui includes
@@ -2,40 +2,45 @@

from types import MethodType

_QVariant__repr__ = QVariant.__repr__
_QVariant__eq__ = QVariant.__eq__
_QVariant__ne__ = QVariant.__ne__
_QVariant__hash__ = QVariant.__hash__


def __nonzero__(self):
if self.isNull():
return False
else:
return super().__nonzero__()
return True


def __repr__(self):
if self.isNull():
return 'NULL'
else:
return super().__repr__(self)
return _QVariant__repr__(self)


def __eq__(self, other):
if self.isNull():
return (isinstance(other, QVariant) and other.isNull())or other is None
else:
return super().__eq__(self, other)
return _QVariant__eq__(self, other)


def __ne__(self, other):
if self.isNull():
return not (isinstance(other, QVariant) and other.isNull()) and other is not None
else:
return super().__ne__(self, other)
return _QVariant__ne__(self, other)


def __hash__(self):
if self.isNull():
return 2178309
else:
return super.__hash__(self)
return _QVariant__hash__(self)

QVariant.__nonzero__ = __nonzero__
QVariant.__repr__ = __repr__
@@ -19,12 +19,14 @@ which are not wrapped by PyQt:
- QList< QPair< QString, QList<QString> > >
- QVector<TYPE*>
- QMap<qint64, QgsFeature*>
- NULL QVariant which is missing in PyQt5 with sip.enableautoconversion
*/

%Feature QSETINT_CONVERSION
%Feature QSETTYPE_CONVERSION
%Feature QLISTCONSTPTR_CONVERSION
%Feature QVECTORINT_CONVERSION
%Feature CHIMERA_NULL_VARIANT_CONVERSION

%ModuleHeaderCode

@@ -1965,6 +1967,7 @@ template <TYPE>
};
%End

%If (CHIMERA_NULL_VARIANT_CONVERSION)
%ModuleHeaderCode
#include "qgissiphelper.h"
%End
@@ -1976,3 +1979,4 @@ void (*register_from_qvariant_convertor)(FromQVariantConvertorFn);
register_from_qvariant_convertor = (void (*)(FromQVariantConvertorFn))sipImportSymbol("pyqt5_register_from_qvariant_convertor");
register_from_qvariant_convertor(null_from_qvariant_convertor);
%End
%End
@@ -33,7 +33,6 @@ INCLUDE_DIRECTORIES(
.
)

ADD_CUSTOM_TARGET(generate_sip_core_cpp_files DEPENDS ${SIP_CORE_CPP_FILES})
ADD_LIBRARY(qgis_sip_helpers OBJECT ${QGIS_SIP_HELPER_SRCS} ${QGIS_SIP_HELPER_HDRS})
ADD_DEPENDENCIES(qgis_sip_helpers generate_sip_core_cpp_files)
ADD_DEPENDENCIES(qgis_sip_helpers generate_sip_qgis._core_cpp_files)
SET_TARGET_PROPERTIES(qgis_sip_helpers PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
@@ -24,22 +24,25 @@

bool null_from_qvariant_convertor( const QVariant *varp, PyObject **objp )
{
if ( varp->isNull() )
{
#if 0
PyObject *tobj = sipConvertFromType(( void * )varp, sipType_QVariant, sipTransferObj );
Py_INCREF( Py_None );
*objp = Py_None;
#endif
static bool watchdog = false;
static bool watchdog = false;

if ( watchdog )
return false;
if ( watchdog )
return false;

// If we deal with a NULL QVariant (and it's not a QByteArray which properly
// maps NULL values)
// If there are more cases like this, we should consider to using a whitelist
// instead of a blacklist.
if ( varp->isNull() && varp->type() != QVariant::ByteArray )
{
watchdog = true;
*objp = PyObject_Call(( PyObject * )sipTypeAsPyTypeObject( sipType_QVariant ), PyTuple_New( 0 ), nullptr );
PyObject* vartype = sipConvertFromEnum( varp->type(), sipType_QVariant_Type );
*objp = PyObject_Call(( PyObject * )sipTypeAsPyTypeObject( sipType_QVariant ), PyTuple_Pack( 1, vartype ), nullptr );
watchdog = false;
return true;
}
return false;
else
{
return false;
}
}
@@ -6,6 +6,9 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from __future__ import print_function
from builtins import str
from builtins import object
__author__ = 'Matthias Kuhn'
__date__ = '2015-04-27'
__copyright__ = 'Copyright 2015, The QGIS Project'
@@ -55,7 +58,7 @@ def testGetFeatures(self):
3: None,
4: 'Point(-65.32 78.3)',
5: 'Point(-71.123 78.23)'}
for pk, geom in expected_geometries.iteritems():
for pk, geom in expected_geometries.items():
if geom:
assert compareWkt(geom, geometries[pk]), "Geometry {} mismatch Expected:\n{}\nGot:\n{}\n".format(pk, geom, geometries[pk].exportToWkt())
else:
@@ -500,7 +503,7 @@ def testGetFeaturesSubsetAttributes(self):
'cnt': set([-200, 300, 100, 200, 400]),
'name': set(['Pear', 'Orange', 'Apple', 'Honey', NULL]),
'name2': set(['NuLl', 'PEaR', 'oranGe', 'Apple', 'Honey'])}
for field, expected in tests.iteritems():
for field, expected in tests.items():
result = set([f[field] for f in self.provider.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([field], self.provider.fields()))])
self.assertEqual(result, expected, 'Expected {}, got {}'.format(expected, result))

0 comments on commit 7dfc696

Please sign in to comment.