mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-10 00:08:20 -05:00
Add unit tests, fix sip annotation
This commit is contained in:
parent
75340527d0
commit
ac74fb6b0a
@ -46,7 +46,8 @@ Returns a list of the device IDs of available 2D map controllers.
|
|||||||
.. seealso:: :py:func:`register2DMapController`
|
.. seealso:: :py:func:`register2DMapController`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsAbstract2DMapController *create2DMapController( const QString &deviceId ) const /Factory/;
|
|
||||||
|
QgsAbstract2DMapController *create2DMapController( const QString &deviceId ) const /TransferBack/;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns a new instance of the 2D map controller with the specified ``deviceId``.
|
Returns a new instance of the 2D map controller with the specified ``deviceId``.
|
||||||
|
|
||||||
@ -78,7 +79,8 @@ Returns a list of the device IDs of available 3D map controllers.
|
|||||||
.. seealso:: :py:func:`register3DMapController`
|
.. seealso:: :py:func:`register3DMapController`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QgsAbstract3DMapController *create3DMapController( const QString &deviceId ) const /Factory/;
|
|
||||||
|
QgsAbstract3DMapController *create3DMapController( const QString &deviceId ) const /TransferBack/;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns a new instance of the 3D map controller with the specified ``deviceId``.
|
Returns a new instance of the 3D map controller with the specified ``deviceId``.
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,21 @@ class GUI_EXPORT QgsInputControllerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
QStringList available2DMapControllers() const;
|
QStringList available2DMapControllers() const;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
|
||||||
|
* the case.
|
||||||
|
* As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
|
||||||
|
*
|
||||||
|
* "
|
||||||
|
* /Factory/ is used when the instance returned is guaranteed to be new to Python.
|
||||||
|
* In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
|
||||||
|
* (However for a different sub-class implemented in C++ then it would be the first time it was seen
|
||||||
|
* by Python so the /Factory/ on create() would be correct.)
|
||||||
|
*
|
||||||
|
* You might try using /TransferBack/ on create() instead - that might be the best compromise.
|
||||||
|
* "
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of the 2D map controller with the specified \a deviceId.
|
* Returns a new instance of the 2D map controller with the specified \a deviceId.
|
||||||
*
|
*
|
||||||
@ -68,7 +83,7 @@ class GUI_EXPORT QgsInputControllerManager : public QObject
|
|||||||
*
|
*
|
||||||
* \see available2DMapControllers()
|
* \see available2DMapControllers()
|
||||||
*/
|
*/
|
||||||
QgsAbstract2DMapController *create2DMapController( const QString &deviceId ) const SIP_FACTORY;
|
QgsAbstract2DMapController *create2DMapController( const QString &deviceId ) const SIP_TRANSFERBACK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new 2D map \a controller.
|
* Registers a new 2D map \a controller.
|
||||||
@ -90,6 +105,21 @@ class GUI_EXPORT QgsInputControllerManager : public QObject
|
|||||||
*/
|
*/
|
||||||
QStringList available3DMapControllers() const;
|
QStringList available3DMapControllers() const;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
|
||||||
|
* the case.
|
||||||
|
* As per Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
|
||||||
|
*
|
||||||
|
* "
|
||||||
|
* /Factory/ is used when the instance returned is guaranteed to be new to Python.
|
||||||
|
* In this case it isn't because it has already been seen when being returned by QgsProcessingAlgorithm::createInstance()
|
||||||
|
* (However for a different sub-class implemented in C++ then it would be the first time it was seen
|
||||||
|
* by Python so the /Factory/ on create() would be correct.)
|
||||||
|
*
|
||||||
|
* You might try using /TransferBack/ on create() instead - that might be the best compromise.
|
||||||
|
* "
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of the 3D map controller with the specified \a deviceId.
|
* Returns a new instance of the 3D map controller with the specified \a deviceId.
|
||||||
*
|
*
|
||||||
@ -99,7 +129,7 @@ class GUI_EXPORT QgsInputControllerManager : public QObject
|
|||||||
*
|
*
|
||||||
* \see available3DMapControllers()
|
* \see available3DMapControllers()
|
||||||
*/
|
*/
|
||||||
QgsAbstract3DMapController *create3DMapController( const QString &deviceId ) const SIP_FACTORY;
|
QgsAbstract3DMapController *create3DMapController( const QString &deviceId ) const SIP_TRANSFERBACK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new 3D map \a controller.
|
* Registers a new 3D map \a controller.
|
||||||
|
|||||||
@ -91,7 +91,7 @@ email : sherman at mrcc.com
|
|||||||
#include "qgssymbollayerutils.h"
|
#include "qgssymbollayerutils.h"
|
||||||
#include "qgsvectortilelayer.h"
|
#include "qgsvectortilelayer.h"
|
||||||
#include "qgsscreenhelper.h"
|
#include "qgsscreenhelper.h"
|
||||||
#include "qgsinputcontroller.h"
|
#include "qgs2dmapcontroller.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup gui
|
* \ingroup gui
|
||||||
|
|||||||
@ -140,6 +140,7 @@ ADD_PYTHON_TEST(PyQgsHighlight test_qgshighlight.py)
|
|||||||
ADD_PYTHON_TEST(PyQgsHistoryProviderRegistry test_qgshistoryproviderregistry.py)
|
ADD_PYTHON_TEST(PyQgsHistoryProviderRegistry test_qgshistoryproviderregistry.py)
|
||||||
ADD_PYTHON_TEST(PyQgsImageCache test_qgsimagecache.py)
|
ADD_PYTHON_TEST(PyQgsImageCache test_qgsimagecache.py)
|
||||||
ADD_PYTHON_TEST(PyQgsImageSourceLineEdit test_qgsimagesourcelineedit.py)
|
ADD_PYTHON_TEST(PyQgsImageSourceLineEdit test_qgsimagesourcelineedit.py)
|
||||||
|
ADD_PYTHON_TEST(PyQgsInputController test_qgsinputcontroller.py)
|
||||||
ADD_PYTHON_TEST(PyQgsInterpolatedLineSymbolLayer test_qgsinterpolatedlinesymbollayers.py)
|
ADD_PYTHON_TEST(PyQgsInterpolatedLineSymbolLayer test_qgsinterpolatedlinesymbollayers.py)
|
||||||
ADD_PYTHON_TEST(PyQgsInterval test_qgsinterval.py)
|
ADD_PYTHON_TEST(PyQgsInterval test_qgsinterval.py)
|
||||||
ADD_PYTHON_TEST(PyQgsJsonEdit test_qgsjsonedit.py)
|
ADD_PYTHON_TEST(PyQgsJsonEdit test_qgsjsonedit.py)
|
||||||
|
|||||||
74
tests/src/python/test_qgsinputcontroller.py
Normal file
74
tests/src/python/test_qgsinputcontroller.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""QGIS Unit tests for QgsInputControllerManager
|
||||||
|
|
||||||
|
From build dir, run: ctest -R QgsArcGisRestUtils -V
|
||||||
|
|
||||||
|
.. 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__ = '(C) 2022 by Nyall Dawson'
|
||||||
|
__date__ = '14/07/2022'
|
||||||
|
__copyright__ = 'Copyright 2022, The QGIS Project'
|
||||||
|
|
||||||
|
import qgis # NOQA
|
||||||
|
from qgis.PyQt.QtCore import QDate, QDateTime, Qt, QTime, QTimeZone, QVariant
|
||||||
|
from qgis.gui import (
|
||||||
|
QgsInputControllerManager,
|
||||||
|
QgsAbstract2DMapController,
|
||||||
|
QgsAbstract3DMapController
|
||||||
|
)
|
||||||
|
from qgis.testing import start_app, unittest
|
||||||
|
|
||||||
|
from utilities import unitTestDataPath
|
||||||
|
|
||||||
|
start_app()
|
||||||
|
TEST_DATA_DIR = unitTestDataPath()
|
||||||
|
|
||||||
|
|
||||||
|
class Dummy2dController(QgsAbstract2DMapController):
|
||||||
|
|
||||||
|
def deviceId(self):
|
||||||
|
return 'dummy2d'
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
return Dummy2dController()
|
||||||
|
|
||||||
|
|
||||||
|
class Dummy3dController(QgsAbstract3DMapController):
|
||||||
|
|
||||||
|
def deviceId(self):
|
||||||
|
return 'dummy3d'
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
return Dummy3dController()
|
||||||
|
|
||||||
|
|
||||||
|
class TestQgsInputController(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_registration(self):
|
||||||
|
manager = QgsInputControllerManager()
|
||||||
|
self.assertFalse(manager.available2DMapControllers())
|
||||||
|
self.assertFalse(manager.available3DMapControllers())
|
||||||
|
|
||||||
|
manager.register2DMapController(Dummy2dController())
|
||||||
|
self.assertEqual(manager.available2DMapControllers(), ['dummy2d'])
|
||||||
|
self.assertFalse(manager.available3DMapControllers())
|
||||||
|
|
||||||
|
new_controller = manager.create2DMapController('dummy2d')
|
||||||
|
self.assertIsInstance(new_controller, Dummy2dController)
|
||||||
|
self.assertEqual(new_controller.deviceId(), 'dummy2d')
|
||||||
|
self.assertIsNone(manager.create2DMapController('nope'))
|
||||||
|
|
||||||
|
manager.register3DMapController(Dummy3dController())
|
||||||
|
self.assertEqual(manager.available2DMapControllers(), ['dummy2d'])
|
||||||
|
self.assertEqual(manager.available3DMapControllers(), ['dummy3d'])
|
||||||
|
|
||||||
|
new_controller = manager.create3DMapController('dummy3d')
|
||||||
|
self.assertIsInstance(new_controller, Dummy3dController)
|
||||||
|
self.assertEqual(new_controller.deviceId(), 'dummy3d')
|
||||||
|
self.assertIsNone(manager.create3DMapController('nope'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Loading…
x
Reference in New Issue
Block a user