Skip to content
Permalink
Browse files

add test for QgsReadWriteContext.enterCategory

  • Loading branch information
3nids committed Feb 28, 2018
1 parent d171ca7 commit 0ec7d54c9c2d2857c8aa436dd195e07bb2ad550c
Showing with 57 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +56 −0 tests/src/python/test_qgsreadwritecontext.py
@@ -154,6 +154,7 @@ ADD_PYTHON_TEST(PyQgsTabfileProvider test_provider_tabfile.py)
ADD_PYTHON_TEST(PyQgsTabWidget test_qgstabwidget.py)
ADD_PYTHON_TEST(PyQgsTextRenderer test_qgstextrenderer.py)
ADD_PYTHON_TEST(PyQgsOGRProvider test_provider_ogr.py)
ADD_PYTHON_TEST(PyQgsReadWriteContext test_qgsreadwritecontext.py)
ADD_PYTHON_TEST(PyQgsSearchWidgetToolButton test_qgssearchwidgettoolbutton.py)
ADD_PYTHON_TEST(PyQgsSearchWidgetWrapper test_qgssearchwidgetwrapper.py)
ADD_PYTHON_TEST(PyQgsShortcutsManager test_qgsshortcutsmanager.py)
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsReadWriteContext.
.. 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__ = 'Denis Rouzaud'
__date__ = '28.02.2018'
__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 Qgis, QgsReadWriteContext
from qgis.testing import unittest


class TestQgsReadWriteContext(unittest.TestCase):

def testEnterCategory(self):
context = QgsReadWriteContext()
context.pushMessage('msg0', Qgis.Critical)
with QgsReadWriteContext.enterCategory(context, 'cat1'):
context.pushMessage('msg1', Qgis.Warning)
with QgsReadWriteContext.enterCategory(context, 'cat2', "detail2"):
context.pushMessage('msg2')
context.pushMessage('msg3')
context.pushMessage('msg4')

messages = context.takeMessages()

self.assertEqual(messages[0].message(), 'msg0')
self.assertEqual(messages[0].level(), Qgis.Critical)
self.assertEqual(messages[0].categories(), [])

self.assertEqual(messages[1].message(), 'msg1')
self.assertEqual(messages[1].level(), Qgis.Warning)
self.assertEqual(messages[1].categories(), ['cat1'])

self.assertEqual(messages[2].message(), 'msg2')
self.assertEqual(messages[2].categories(), ['cat1', 'cat2 :: detail2'])

self.assertEqual(messages[3].message(), 'msg3')
self.assertEqual(messages[3].categories(), ['cat1'])

self.assertEqual(messages[4].message(), 'msg4')
self.assertEqual(messages[4].categories(), [])


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

0 comments on commit 0ec7d54

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