Skip to content
Permalink
Browse files

Unit tests for QgsMapLayerFactory

  • Loading branch information
nyalldawson committed Mar 9, 2021
1 parent 63a365a commit e3106ad0701a12d624df9fde3207bfaa88e404e7
Showing with 68 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +67 −0 tests/src/python/test_qgsmaplayerfactory.py
@@ -175,6 +175,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)
@@ -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 e3106ad

Please sign in to comment.