diff --git a/.ci/test_blocklist_qt6.txt b/.ci/test_blocklist_qt6.txt index ea2cf64851c2..d9f926c3565a 100644 --- a/.ci/test_blocklist_qt6.txt +++ b/.ci/test_blocklist_qt6.txt @@ -3,7 +3,6 @@ test_core_compositionconverter test_core_expression test_core_labelingengine test_core_layoutpicture -test_core_ogcutils test_core_vectortilelayer test_gui_processinggui test_app_advanceddigitizing @@ -47,7 +46,6 @@ PyQgsEditWidgets PyQgsElevationProfileCanvas PyQgsProject PyQgsFloatingWidget -PyQgsJsonUtils PyQgsLayoutHtml PyQgsLineSymbolLayers PyQgsMapBoxGlStyleConverter @@ -59,7 +57,6 @@ PyQgsRasterAttributeTable PyQgsRasterLayerRenderer PyQgsShapefileProvider PyQgsTextRenderer -PyQgsOGRProvider PyQgsSpatialiteProvider PyQgsSymbolLayerReadSld PyQgsVectorLayerCache @@ -79,4 +76,3 @@ ProcessingQgisAlgorithmsTestPt3 ProcessingQgisAlgorithmsTestPt4 ProcessingGdalAlgorithmsVectorTest ProcessingGrassAlgorithmsImageryTest -PyQgsProviderRegistry diff --git a/tests/src/python/test_provider_ogr.py b/tests/src/python/test_provider_ogr.py index e3e8c7a740e0..94813a1c6ae0 100644 --- a/tests/src/python/test_provider_ogr.py +++ b/tests/src/python/test_provider_ogr.py @@ -18,7 +18,7 @@ from datetime import datetime from osgeo import gdal, ogr # NOQA -from qgis.PyQt.QtCore import QByteArray, QTemporaryDir, QVariant +from qgis.PyQt.QtCore import QT_VERSION_STR, QByteArray, QTemporaryDir, QVariant from qgis.PyQt.QtXml import QDomDocument from qgis.core import ( NULL, @@ -1092,7 +1092,10 @@ def testBoolFieldEvaluation(self): self.assertEqual(vl.fields().at(0).name(), 'bool') self.assertEqual(vl.fields().at(0).type(), QVariant.Bool) self.assertEqual([f[0] for f in vl.getFeatures()], [True, False, NULL]) - self.assertEqual([f[0].__class__.__name__ for f in vl.getFeatures()], ['bool', 'bool', 'QVariant']) + if int(QT_VERSION_STR.split('.')[0]) >= 6: + self.assertEqual([f[0].__class__.__name__ for f in vl.getFeatures()], ['bool', 'bool', 'NoneType']) + else: + self.assertEqual([f[0].__class__.__name__ for f in vl.getFeatures()], ['bool', 'bool', 'QVariant']) def testReloadDataAndFeatureCount(self): @@ -1155,8 +1158,7 @@ def testSpatialiteDefaultValues(self): # Test default values dp = vl.dataProvider() - # FIXME: should it be None? - self.assertTrue(dp.defaultValue(0).isNull()) + self.assertEqual(dp.defaultValue(0), NULL) self.assertIsNone(dp.defaultValue(1)) # FIXME: This fails because there is no backend-side evaluation in this provider # self.assertTrue(dp.defaultValue(2).startswith(now.strftime('%Y-%m-%d'))) @@ -1404,7 +1406,16 @@ def testHTTPRequestsOverrider(self): # Asked when ogr provider try to open. See QgsOgrProvider::QgsOgrProvider#453 open( OpenModeForceReadOnly ); handler.add('GET', '/collections/foo', 200, {'Content-Type': 'application/json'}, '{ "id": "foo" }') - if int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 9, 0): + # 3.8.3 not necessarily the minimum version + if int(gdal.VersionInfo('VERSION_NUM')) >= GDAL_COMPUTE_VERSION(3, 8, 3): + handler.add('GET', '/', 200, {'Content-Type': 'application/json'}, '{ "id": "foo" }') + handler.add('GET', '/api', 200, {'Content-Type': 'application/json'}, '{ "id": "foo" }') + + handler.add('GET', '/collections/foo/items?limit=20', 200, {'Content-Type': 'application/geo+json'}, + '{ "type": "FeatureCollection", "features": [] }') + handler.add('GET', '/collections/foo/items?limit=1000', 200, {'Content-Type': 'application/geo+json'}, + '{ "type": "FeatureCollection", "features": [] }') + else: # See QgsOgrProvider::open#4012 mOgrOrigLayer = QgsOgrProviderUtils::getLayer( mFilePath, false, options, mLayerName, errCause, true ); handler.add('GET', '/collections/foo/items?limit=10', 200, {'Content-Type': 'application/geo+json'}, '{ "type": "FeatureCollection", "features": [] }') @@ -1417,17 +1428,6 @@ def testHTTPRequestsOverrider(self): handler.add('GET', '/collections/foo/items?limit=10', 200, {'Content-Type': 'application/geo+json'}, '{ "type": "FeatureCollection", "features": [] }') - else: - handler.add('GET', '/', 200, {'Content-Type': 'application/json'}, '{ "id": "foo" }') - handler.add('GET', '/api', 200, {'Content-Type': 'application/json'}, '{ "id": "foo" }') - - handler.add('GET', '/collections/foo/items?limit=20', 200, {'Content-Type': 'application/geo+json'}, - '{ "type": "FeatureCollection", "features": [] }') - handler.add('GET', '/collections/foo/items?limit=1000', 200, {'Content-Type': 'application/geo+json'}, - '{ "type": "FeatureCollection", "features": [] }') - handler.add('GET', '/collections/foo/items?limit=1000', 200, {'Content-Type': 'application/geo+json'}, - '{ "type": "FeatureCollection", "features": [] }') - with mockedwebserver.install_http_handler(handler): vl = QgsVectorLayer("OAPIF:http://127.0.0.1:%d/collections/foo" % port, 'test', 'ogr') self.assertTrue(vl.isValid()) diff --git a/tests/src/python/test_provider_spatialite.py b/tests/src/python/test_provider_spatialite.py index c00e91dedebe..74389c622725 100644 --- a/tests/src/python/test_provider_spatialite.py +++ b/tests/src/python/test_provider_spatialite.py @@ -1561,8 +1561,7 @@ def testSpatialiteDefaultValues(self): # Test default values dp = vl.dataProvider() - # FIXME: should it be None? - self.assertTrue(dp.defaultValue(0).isNull()) + self.assertEqual(dp.defaultValue(0), NULL) self.assertIsNone(dp.defaultValue(1)) # FIXME: This fails because there is no backend-side evaluation in this provider # self.assertTrue(dp.defaultValue(2).startswith(now.strftime('%Y-%m-%d'))) diff --git a/tests/src/python/test_qgsjsonutils.py b/tests/src/python/test_qgsjsonutils.py index 6b14d88df317..30915b0c3a6b 100644 --- a/tests/src/python/test_qgsjsonutils.py +++ b/tests/src/python/test_qgsjsonutils.py @@ -9,7 +9,7 @@ __date__ = '3/05/2016' __copyright__ = 'Copyright 2016, The QGIS Project' -from qgis.PyQt.QtCore import QLocale, Qt, QTextCodec, QVariant +from qgis.PyQt.QtCore import QT_VERSION_STR, QLocale, Qt, QVariant from qgis.core import ( NULL, QgsCoordinateReferenceSystem, @@ -31,7 +31,10 @@ from qgis.testing import start_app, QgisTestCase start_app() -codec = QTextCodec.codecForName("System") + +if int(QT_VERSION_STR.split('.')[0]) < 6: + from qgis.PyQt.QtCore import QTextCodec + codec = QTextCodec.codecForName("System") class TestQgsJsonUtils(QgisTestCase): @@ -42,17 +45,25 @@ def testStringToFeatureList(self): fields.append(QgsField("name", QVariant.String)) # empty string - features = QgsJsonUtils.stringToFeatureList("", fields, codec) + if int(QT_VERSION_STR.split('.')[0]) >= 6: + features = QgsJsonUtils.stringToFeatureList("", fields) + else: + features = QgsJsonUtils.stringToFeatureList("", fields, codec) self.assertEqual(features, []) # bad string - features = QgsJsonUtils.stringToFeatureList("asdasdas", fields, codec) + if int(QT_VERSION_STR.split('.')[0]) >= 6: + features = QgsJsonUtils.stringToFeatureList("asdasdas", fields) + else: + features = QgsJsonUtils.stringToFeatureList("asdasdas", fields, codec) self.assertEqual(features, []) # geojson string with 1 feature - features = QgsJsonUtils.stringToFeatureList( - '{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands"}}', - fields, codec) + s = '{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands"}}' + if int(QT_VERSION_STR.split('.')[0]) >= 6: + features = QgsJsonUtils.stringToFeatureList(s, fields) + else: + features = QgsJsonUtils.stringToFeatureList(s, fields, codec) self.assertEqual(len(features), 1) self.assertFalse(features[0].geometry().isNull()) self.assertEqual(features[0].geometry().wkbType(), QgsWkbTypes.Type.Point) @@ -62,9 +73,11 @@ def testStringToFeatureList(self): self.assertEqual(features[0]['name'], "Dinagat Islands") # geojson string with 2 features - features = QgsJsonUtils.stringToFeatureList( - '{ "type": "FeatureCollection","features":[{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands"}}, {\n"type": "Feature","geometry": {"type": "Point","coordinates": [110, 20]},"properties": {"name": "Henry Gale Island"}}]}', - fields, codec) + s = '{ "type": "FeatureCollection","features":[{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands"}}, {\n"type": "Feature","geometry": {"type": "Point","coordinates": [110, 20]},"properties": {"name": "Henry Gale Island"}}]}' + if int(QT_VERSION_STR.split('.')[0]) >= 6: + features = QgsJsonUtils.stringToFeatureList(s, fields) + else: + features = QgsJsonUtils.stringToFeatureList(s, fields, codec) self.assertEqual(len(features), 2) self.assertFalse(features[0].geometry().isNull()) self.assertEqual(features[0].geometry().wkbType(), QgsWkbTypes.Type.Point) @@ -121,17 +134,25 @@ def testStringToFields(self): """test retrieving fields from GeoJSON strings""" # empty string - fields = QgsJsonUtils.stringToFields("", codec) + if int(QT_VERSION_STR.split('.')[0]) >= 6: + fields = QgsJsonUtils.stringToFields("") + else: + fields = QgsJsonUtils.stringToFields("", codec) self.assertEqual(fields.count(), 0) # bad string - fields = QgsJsonUtils.stringToFields("asdasdas", codec) + if int(QT_VERSION_STR.split('.')[0]) >= 6: + fields = QgsJsonUtils.stringToFields("asdasdas") + else: + fields = QgsJsonUtils.stringToFields("asdasdas", codec) self.assertEqual(fields.count(), 0) # geojson string - fields = QgsJsonUtils.stringToFields( - '{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands","height":5.5}}', - codec) + s = '{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands","height":5.5}}' + if int(QT_VERSION_STR.split('.')[0]) >= 6: + fields = QgsJsonUtils.stringToFields(s) + else: + fields = QgsJsonUtils.stringToFields(s, codec) self.assertEqual(fields.count(), 2) self.assertEqual(fields[0].name(), "name") self.assertEqual(fields[0].type(), QVariant.String) @@ -139,9 +160,11 @@ def testStringToFields(self): self.assertEqual(fields[1].type(), QVariant.Double) # geojson string with 2 features - fields = QgsJsonUtils.stringToFields( - '{ "type": "FeatureCollection","features":[{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands","height":5.5}}, {\n"type": "Feature","geometry": {"type": "Point","coordinates": [110, 20]},"properties": {"name": "Henry Gale Island","height":6.5}}]}', - codec) + s = '{ "type": "FeatureCollection","features":[{\n"type": "Feature","geometry": {"type": "Point","coordinates": [125, 10]},"properties": {"name": "Dinagat Islands","height":5.5}}, {\n"type": "Feature","geometry": {"type": "Point","coordinates": [110, 20]},"properties": {"name": "Henry Gale Island","height":6.5}}]}' + if int(QT_VERSION_STR.split('.')[0]) >= 6: + fields = QgsJsonUtils.stringToFields(s) + else: + fields = QgsJsonUtils.stringToFields(s, codec) self.assertEqual(fields.count(), 2) self.assertEqual(fields[0].name(), "name") self.assertEqual(fields[0].type(), QVariant.String)