Skip to content
Permalink
Browse files

add tests for new methods

  • Loading branch information
alexbruy committed Dec 11, 2017
1 parent 79d83f2 commit 33fdf8f21929a44a34b5e291658434fb8bd8ac7e
Showing with 28 additions and 2 deletions.
  1. +2 −2 src/core/raster/qgsrasterfilewriter.cpp
  2. +26 −0 tests/src/python/test_qgsrasterfilewriter.py
@@ -1039,9 +1039,9 @@ QString QgsRasterFileWriter::filterForDriver( const QString &driverName )
QString filter = drvName + " (";
for ( const QString &ext : extensions )
{
filter.append( QStringLiteral( "*.%1 *.%2" ).arg( ext.toLower(), ext.toUpper() ) );
filter.append( QStringLiteral( "*.%1 *.%2 " ).arg( ext.toLower(), ext.toUpper() ) );
}
filter.append( QStringLiteral( ")" ) );
filter = filter.trimmed().append( QStringLiteral( ")" ) );
return filter;
}

@@ -114,6 +114,32 @@ def testExtensionsForFormat(self):
self.assertCountEqual(QgsRasterFileWriter.extensionsForFormat('GTiff'), ['tiff', 'tif'])
self.assertCountEqual(QgsRasterFileWriter.extensionsForFormat('GPKG'), ['gpkg'])

def testSupportedFiltersAndFormat(self):
# test with formats in recommended order
formats = QgsRasterFileWriter.supportedFiltersAndFormats(QgsRasterFileWriter.SortRecommended)
self.assertEqual(formats[0].filterString, 'GeoTIFF (*.tif *.TIF *.tiff *.TIFF)')
self.assertEqual(formats[0].driverName, 'GTiff')
self.assertTrue('netCDF' in [f.driverName for f in formats])

# alphabetical sorting
formats2 = QgsRasterFileWriter.supportedFiltersAndFormats(QgsRasterFileWriter.RasterFormatOptions())
self.assertTrue(formats2[0].driverName < formats2[1].driverName)
self.assertCountEqual([f.driverName for f in formats], [f.driverName for f in formats2])
self.assertNotEqual(formats2[0].driverName, 'GTiff')

def testSupportedFormatExtensions(self):
formats = QgsRasterFileWriter.supportedFormatExtensions()
self.assertTrue('tif' in formats)
self.assertFalse('exe' in formats)
self.assertEqual(formats[0], 'tif')
self.assertTrue('nc' in formats)

# alphabetical sorting
formats2 = QgsRasterFileWriter.supportedFormatExtensions(QgsRasterFileWriter.RasterFormatOptions())
self.assertTrue(formats2[1] < formats2[2])
self.assertCountEqual(formats, formats2)
self.assertNotEqual(formats2[0], 'tif')

def testImportIntoGpkg(self):
# init target file
test_gpkg = tempfile.mktemp(suffix='.gpkg', dir=self.testDataDir)

0 comments on commit 33fdf8f

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