Skip to content
Permalink
Browse files

fix QgsProject::readNumEntry() validity check (#4112)

  • Loading branch information
nirvn committed Feb 7, 2017
1 parent 0f5b3fd commit 6f2045fd8471ed0541fb324cd4d81cea196d8135
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/core/qgsproject.cpp
  2. +13 −0 tests/src/python/test_qgsproject.py
@@ -1432,7 +1432,7 @@ int QgsProject::readNumEntry( const QString& scope, const QString &key, int def,
value = property->value();
}

bool valid = value.canConvert( QVariant::String );
bool valid = value.canConvert( QVariant::Int );

if ( ok )
{
@@ -14,13 +14,17 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os

import qgis # NOQA

from qgis.core import QgsProject, QgsApplication, QgsUnitTypes, QgsCoordinateReferenceSystem

from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)

start_app()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsProject(unittest.TestCase):
@@ -140,5 +144,14 @@ def testAreaUnits(self):
prj.setAreaUnits(QgsUnitTypes.AreaSquareFeet)
self.assertEqual(prj.areaUnits(), QgsUnitTypes.AreaSquareFeet)

def testReadEntry(self):
prj = QgsProject.instance()
prj.read(os.path.join(TEST_DATA_DIR, 'labeling/test-labeling.qgs'))

#valid key, valid int value
self.assertEqual(prj.readNumEntry("SpatialRefSys", "/ProjectionsEnabled", -1)[0], 0)
#invalid key
self.assertEqual(prj.readNumEntry("SpatialRefSys", "/InvalidKey", -1)[0], -1)

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

0 comments on commit 6f2045f

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