Skip to content

Commit

Permalink
Merge pull request #39091 from rouault/tests_gdal_skipif
Browse files Browse the repository at this point in the history
tests: replace wrong uses of unittest.skip() by unittest.skipIf()
  • Loading branch information
m-kuhn committed Sep 30, 2020
2 parents a0ec119 + 9083c56 commit cebc51b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
18 changes: 13 additions & 5 deletions tests/src/python/test_provider_ogr.py
Expand Up @@ -526,7 +526,7 @@ def testBinaryField(self):
self.assertIsInstance(features[2]['DATA'], QByteArray)
self.assertEqual(hashlib.md5(features[2]['DATA'].data()).hexdigest(), '4b952b80e4288ca5111be2f6dd5d6809')

@unittest.skip(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0))
@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0), "GDAL 2.4 required")
def testStringListField(self):
source = os.path.join(TEST_DATA_DIR, 'stringlist.gml')
vl = QgsVectorLayer(source)
Expand Down Expand Up @@ -730,7 +730,7 @@ def testMixOfFilterExpressionAndSubsetStringWhenFilterExpressionCompilationFails

self.assertCountEqual([f.attributes() for f in vl.getFeatures(request)], [['rectangle', '1']])

@unittest.skip(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 2, 0))
@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(3, 2, 0), "GDAL 3.2 required")
def testFieldAliases(self):
"""
Test that field aliases are taken from OGR where available (requires GDAL 3.2 or later)
Expand All @@ -740,9 +740,17 @@ def testFieldAliases(self):
self.assertTrue(vl.isValid())

fields = vl.fields()
self.assertEqual([f.name() for f in fields], ['OBJECTID', 'text', 'short_int', 'long_int', 'float', 'double', 'date', 'blob', 'guid', 'raster', 'SHAPE_Length', 'SHAPE_Area'])
self.assertEqual([f.alias() for f in fields],
['', 'My Text Field', 'My Short Int Field', 'My Long Int Field', 'My Float Field', 'My Double Field', 'My Date Field', 'My Blob Field', 'My GUID field', 'My Raster Field', '', ''])

# proprietary FileGDB driver doesn't have the raster column
if 'raster' not in set(f.name() for f in fields):
expected_fieldnames = ['OBJECTID', 'text', 'short_int', 'long_int', 'float', 'double', 'date', 'blob', 'guid', 'SHAPE_Length', 'SHAPE_Area']
expected_alias = ['', 'My Text Field', 'My Short Int Field', 'My Long Int Field', 'My Float Field', 'My Double Field', 'My Date Field', 'My Blob Field', 'My GUID field', '', '']
else:
expected_fieldnames = ['OBJECTID', 'text', 'short_int', 'long_int', 'float', 'double', 'date', 'blob', 'guid', 'raster', 'SHAPE_Length', 'SHAPE_Area']
expected_alias = ['', 'My Text Field', 'My Short Int Field', 'My Long Int Field', 'My Float Field', 'My Double Field', 'My Date Field', 'My Blob Field', 'My GUID field', 'My Raster Field', '', '']

self.assertEqual([f.name() for f in fields], expected_fieldnames)
self.assertEqual([f.alias() for f in fields], expected_alias)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_provider_ogr_gpkg.py
Expand Up @@ -389,7 +389,7 @@ def testBug15351_commit_closeProvider_closeIter(self):
def testBug15351_commit_closeIter_closeProvider(self):
self.internalTestBug15351('commit_closeIter_closeProvider')

@unittest.skip(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 1, 2))
@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 1, 2), 'GDAL 2.1.2 required')
def testGeopackageExtentUpdate(self):
''' test https://github.com/qgis/QGIS/issues/23209 '''
tmpfile = os.path.join(self.basetestpath, 'testGeopackageExtentUpdate.gpkg')
Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgsvectorfilewriter.py
Expand Up @@ -1045,13 +1045,14 @@ def testDropZ(self):
f = next(created_layer.getFeatures(QgsFeatureRequest()))
self.assertEqual(f.geometry().asWkt(), 'Point (10 10)')

@unittest.skip(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0))
@unittest.skipIf(int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0), "GDAL 2.4.0 required")
def testWriteWithStringListField(self):
"""
Test writing with a string list field
:return:
"""
tmpfile = os.path.join(self.basetestpath, 'newstringlistfield.gml')
basetestpath = tempfile.mkdtemp()
tmpfile = os.path.join(basetestpath, 'newstringlistfield.gml')
ds = ogr.GetDriverByName('GML').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint)
lyr.CreateField(ogr.FieldDefn('strfield', ogr.OFTString))
Expand Down

0 comments on commit cebc51b

Please sign in to comment.