Skip to content

Commit

Permalink
Start on unit tests for numeric format gui
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 8, 2020
1 parent 6b9cafb commit 6088edd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -155,6 +155,7 @@ ADD_PYTHON_TEST(PyQgsNetworkContentFetcherRegistry test_qgsnetworkcontentfetcher
ADD_PYTHON_TEST(PyQgsNetworkContentFetcherTask test_qgsnetworkcontentfetchertask.py) ADD_PYTHON_TEST(PyQgsNetworkContentFetcherTask test_qgsnetworkcontentfetchertask.py)
ADD_PYTHON_TEST(PyQgsNullSymbolRenderer test_qgsnullsymbolrenderer.py) ADD_PYTHON_TEST(PyQgsNullSymbolRenderer test_qgsnullsymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsNumericFormat test_qgsnumericformat.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(PyQgsNewGeoPackageLayerDialog test_qgsnewgeopackagelayerdialog.py)
ADD_PYTHON_TEST(PyQgsNoApplication test_qgsnoapplication.py) ADD_PYTHON_TEST(PyQgsNoApplication test_qgsnoapplication.py)
ADD_PYTHON_TEST(PyQgsOgcUtils test_qgsogcutils.py) ADD_PYTHON_TEST(PyQgsOgcUtils test_qgsogcutils.py)
Expand Down
12 changes: 11 additions & 1 deletion tests/src/python/test_qgsnumericformat.py
Expand Up @@ -37,6 +37,9 @@ def id(self):
def formatDouble(self, value, context): def formatDouble(self, value, context):
return 'xxx' + str(value) return 'xxx' + str(value)


def visibleName(self):
return 'Test'

def clone(self): def clone(self):
return TestFormat() return TestFormat()


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


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


self.assertTrue(isinstance(registry.fallbackFormat(), QgsFallbackNumericFormat)) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
53 changes: 53 additions & 0 deletions tests/src/python/test_qgsnumericformatgui.py
@@ -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.