Skip to content
Permalink
Browse files

Start on unit tests for numeric format gui

  • Loading branch information
nyalldawson committed Jan 7, 2020
1 parent 6b9cafb commit 6088eddaeee3df39a9de490b9158a98244a50b0c
@@ -155,6 +155,7 @@ ADD_PYTHON_TEST(PyQgsNetworkContentFetcherRegistry test_qgsnetworkcontentfetcher
ADD_PYTHON_TEST(PyQgsNetworkContentFetcherTask test_qgsnetworkcontentfetchertask.py)
ADD_PYTHON_TEST(PyQgsNullSymbolRenderer test_qgsnullsymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsNumericFormat test_qgsnumericformat.py)
ADD_PYTHON_TEST(PyQgsNumericFormatGui test_qgsnumericformatgui.py)
ADD_PYTHON_TEST(PyQgsNewGeoPackageLayerDialog test_qgsnewgeopackagelayerdialog.py)
ADD_PYTHON_TEST(PyQgsNoApplication test_qgsnoapplication.py)
ADD_PYTHON_TEST(PyQgsOgcUtils test_qgsogcutils.py)
@@ -37,6 +37,9 @@ def id(self):
def formatDouble(self, value, context):
return 'xxx' + str(value)

def visibleName(self):
return 'Test'

def clone(self):
return TestFormat()

@@ -561,7 +564,7 @@ def testRegistry(self):
for f in registry.formats():
self.assertEqual(registry.format(f).id(), f)

self.assertNotIn('default', registry.formats())
self.assertIn('default', registry.formats())
registry.addFormat(TestFormat())
self.assertIn('test', registry.formats())
self.assertTrue(isinstance(registry.format('test'), TestFormat))
@@ -575,6 +578,13 @@ def testRegistry(self):

self.assertTrue(isinstance(registry.fallbackFormat(), QgsFallbackNumericFormat))

self.assertEqual(registry.visibleName('default'), 'General')
self.assertEqual(registry.visibleName('basic'), 'Number')

self.assertEqual(registry.sortKey('default'), 0)
self.assertEqual(registry.sortKey('basic'), 1)
self.assertEqual(registry.sortKey('currency'), 100)


if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsNumericFormat GUI components
.. 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__ = '6/01/2020'
__copyright__ = 'Copyright 2020, The QGIS Project'

import qgis # NOQA

from qgis.core import (QgsFallbackNumericFormat,
QgsBasicNumericFormat,
QgsNumericFormatContext,
QgsBearingNumericFormat,
QgsPercentageNumericFormat,
QgsScientificNumericFormat,
QgsCurrencyNumericFormat,
QgsNumericFormatRegistry,
QgsNumericFormat,
QgsReadWriteContext)

from qgis.gui import QgsNumericFormatSelectorWidget

from qgis.testing import start_app, unittest
from qgis.PyQt.QtTest import QSignalSpy

start_app()


class TestQgsNumericFormatGui(unittest.TestCase):

def testSelectorWidget(self):
w = QgsNumericFormatSelectorWidget()
spy = QSignalSpy(w.changed)
# should default to a default format
self.assertIsInstance(w.format(), QgsFallbackNumericFormat)

w.setFormat(QgsBearingNumericFormat())
self.assertIsInstance(w.format(), QgsBearingNumericFormat)
self.assertEqual(len(spy), 1)
w.setFormat(QgsBearingNumericFormat())
self.assertEqual(len(spy), 1)
w.setFormat(QgsCurrencyNumericFormat())
self.assertIsInstance(w.format(), QgsCurrencyNumericFormat)
self.assertEqual(len(spy), 2)


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

0 comments on commit 6088edd

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