-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some extension and filter handling functions to QgsFileUtils
- Loading branch information
1 parent
48e6ec5
commit 128e37e
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsFileUtils. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Nyall Dawson' | ||
__date__ = '18/12/2017' | ||
__copyright__ = 'Copyright 2017, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis # NOQA | ||
|
||
from qgis.core import QgsFileUtils | ||
from qgis.testing import unittest | ||
|
||
|
||
class TestQgsFileUtils(unittest.TestCase): | ||
|
||
def testExtensionsFromFilter(self): | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter(''), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('bad'), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('*'), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('*.'), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('Tiff files'), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('(*.)'), []) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('PNG Files (*.png)'), ['png']) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('PNG Files (*.PNG)'), ['PNG']) | ||
self.assertEqual(QgsFileUtils.extensionsFromFilter('Geotiff Files (*.tiff *.tif)'), ['tiff', 'tif']) | ||
|
||
def testEnsureFileNameHasExtension(self): | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('', ['']), '') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('', []), '') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test', []), 'test') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('', ['.tif']), '') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test', ['.tif']), 'test.tif') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test', ['tif']), 'test.tif') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test.tif', []), 'test.tif') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test.tif', ['bmp']), 'test.tif.bmp') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test.tif', ['tiff']), 'test.tif.tiff') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test.tif', ['tiff', 'tif']), 'test.tif') | ||
self.assertEqual(QgsFileUtils.ensureFileNameHasExtension('test.tif', ['TIFF', 'TIF']), 'test.tif') | ||
|
||
def testAddExtensionFromFilter(self): | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test', 'TIFF Files (*.tif)'), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test', 'TIFF Files (*.tif)'), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', ''), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', 'BMP Files (*.bmp)'), 'test.tif.bmp') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', 'TIFF Files (*.tiff)'), 'test.tif.tiff') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', 'TIFF Files (*.tif *.tiff)'), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', 'TIFF Files (*.TIF *.TIFF)'), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test.tif', 'All Files (*.*)'), 'test.tif') | ||
self.assertEqual(QgsFileUtils.addExtensionFromFilter('test', 'All Files (*.*)'), 'test') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |