Skip to content
Permalink
Browse files

Add Python unit test

  • Loading branch information
pblottiere committed May 12, 2020
1 parent 86503e5 commit 3cfe500f35de59f2592a4097f0898e64551d1446
Showing with 51 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +50 −0 tests/src/python/test_qgslegendrenderer.py
@@ -138,6 +138,7 @@ ADD_PYTHON_TEST(PyQgsLayoutUnitsComboBox test_qgslayoutunitscombobox.py)
ADD_PYTHON_TEST(PyQgsLegendPatchShape test_qgslegendpatchshape.py)
ADD_PYTHON_TEST(PyQgsLegendPatchShapeButton test_qgslegendpatchshapebutton.py)
ADD_PYTHON_TEST(PyQgsLegendPatchShapeWidget test_qgslegendpatchshapewidget.py)
ADD_PYTHON_TEST(PyQgsLegendRenderer test_qgslegendrenderer.py)
ADD_PYTHON_TEST(PyQgsLineSegment test_qgslinesegment.py)
ADD_PYTHON_TEST(PyQgsLineSymbolLayers test_qgslinesymbollayers.py)
ADD_PYTHON_TEST(PyQgsLocalDefaultSettings test_qgslocaldefaultsettings.py)
@@ -0,0 +1,50 @@
# coding=utf-8
""""Test QgsLegendRenderer JSON export
.. 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.
Run with ctest -V -R PyQgsLegendRenderer
"""

__author__ = 'elpaso@itopen.it'
__date__ = '2020-04-29'
__copyright__ = 'Copyright 2020, ItOpen'

import os

from qgis.core import (
QgsProject,
QgsLegendModel,
QgsLegendSettings,
QgsLegendRenderer,
QgsRenderContext,
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

QGISAPP = start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestPyQgsLegendRenderer(unittest.TestCase):

def test_json_export(self):

project = QgsProject()
self.assertTrue(project.read(os.path.join(unitTestDataPath('qgis_server'), 'test_project.qgs')))
model = QgsLegendModel(project.layerTreeRoot())
ctx = QgsRenderContext()
settings = QgsLegendSettings()
renderer = QgsLegendRenderer(model, settings)
nodes = renderer.exportLegendToJson(ctx)['nodes'].toVariant()
self.assertEqual(len(nodes), 7)
self.assertEqual(nodes[0]['type'], 'layer')
self.assertEqual(nodes[0]['title'], 'testlayer')


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

0 comments on commit 3cfe500

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