Skip to content

Commit

Permalink
add tests for new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 11, 2017
1 parent 79d83f2 commit 33fdf8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/src/python/test_qgsrasterfilewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 33fdf8f

Please sign in to comment.