Skip to content

Commit

Permalink
Unit tests for QgsMapLayerFactory
Browse files Browse the repository at this point in the history
(cherry picked from commit e3106ad)
  • Loading branch information
nyalldawson committed Mar 11, 2021
1 parent 932814c commit 632c9a2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -174,6 +174,7 @@ ADD_PYTHON_TEST(PyQgsMapClippingUtils test_qgsmapclippingutils.py)
ADD_PYTHON_TEST(PyQgsMapLayer test_qgsmaplayer.py)
ADD_PYTHON_TEST(PyQgsMapLayerAction test_qgsmaplayeraction.py)
ADD_PYTHON_TEST(PyQgsMapLayerComboBox test_qgsmaplayercombobox.py)
ADD_PYTHON_TEST(PyQgsMapLayerFactory test_qgsmaplayerfactory.py)
ADD_PYTHON_TEST(PyQgsMapLayerModel test_qgsmaplayermodel.py)
ADD_PYTHON_TEST(PyQgsMapLayerProxyModel test_qgsmaplayerproxymodel.py)
ADD_PYTHON_TEST(PyQgsMapLayerStore test_qgsmaplayerstore.py)
Expand Down
67 changes: 67 additions & 0 deletions tests/src/python/test_qgsmaplayerfactory.py
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsMapLayerFactory.
.. 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__ = '10/03/2021'
__copyright__ = 'Copyright 2021, The QGIS Project'

import qgis # NOQA

from qgis.core import QgsMapLayerFactory, QgsMapLayerType
from qgis.testing import start_app, unittest

start_app()


class TestQgsMapLayerFactory(unittest.TestCase):

def testTypeFromString(self):
"""
Test QgsMapLayerFactory.typeFromString
"""
self.assertEqual(QgsMapLayerFactory.typeFromString('xxx')[1], False)
self.assertEqual(QgsMapLayerFactory.typeFromString('')[1], False)
self.assertEqual(QgsMapLayerFactory.typeFromString('vector'), (QgsMapLayerType.VectorLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('VECTOR'), (QgsMapLayerType.VectorLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('raster'), (QgsMapLayerType.RasterLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('mesh'), (QgsMapLayerType.MeshLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('vector-tile'), (QgsMapLayerType.VectorTileLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('point-cloud'), (QgsMapLayerType.PointCloudLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('plugin'), (QgsMapLayerType.PluginLayer, True))
self.assertEqual(QgsMapLayerFactory.typeFromString('annotation'), (QgsMapLayerType.AnnotationLayer, True))

def testTypeToString(self):
"""
Test QgsMapLayerFactory.typeToString
"""
# test via round trips...
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.VectorLayer))[0],
QgsMapLayerType.VectorLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.RasterLayer))[0],
QgsMapLayerType.RasterLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.MeshLayer))[0],
QgsMapLayerType.MeshLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.VectorTileLayer))[0],
QgsMapLayerType.VectorTileLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.PointCloudLayer))[0],
QgsMapLayerType.PointCloudLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.PluginLayer))[0],
QgsMapLayerType.PluginLayer)
self.assertEqual(
QgsMapLayerFactory.typeFromString(QgsMapLayerFactory.typeToString(QgsMapLayerType.AnnotationLayer))[0],
QgsMapLayerType.AnnotationLayer)


if __name__ == '__main__':
unittest.main()

0 comments on commit 632c9a2

Please sign in to comment.