Skip to content

Commit

Permalink
Fixes to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 16, 2017
1 parent ee9fabb commit bfdc84f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 61 deletions.
4 changes: 3 additions & 1 deletion python/core/qgsvectorlayerlabeling.sip
Expand Up @@ -23,8 +23,10 @@ class QgsAbstractVectorLayerLabeling
#include "qgsvectorlayerlabeling.h"
%End
public:

QgsAbstractVectorLayerLabeling();
%Docstring
Default constructor
%End
virtual ~QgsAbstractVectorLayerLabeling();

virtual QString type() const = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsrulebasedlabeling.h
Expand Up @@ -247,15 +247,19 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
// evaluation

//! add providers
//! \note not available in Python bindings
void createSubProviders( QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider ) SIP_SKIP;

//! append rule keys of descendants that contain valid settings (i.e. they will be sub-providers)
//! \note not available in Python bindings
void subProviderIds( QStringList &list ) const SIP_SKIP;

//! call prepare() on sub-providers and populate attributeNames
//! \note not available in Python bindings
void prepare( const QgsRenderContext &context, QSet<QString> &attributeNames, RuleToProviderMap &subProviders ) SIP_SKIP;

//! register individual features
//! \note not available in Python bindings
RegisterResult registerFeature( QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, QgsGeometry *obstacleGeometry = nullptr ) SIP_SKIP;

/**
Expand Down Expand Up @@ -326,6 +330,7 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
virtual QString type() const override;
virtual QgsRuleBasedLabeling *clone() const override SIP_FACTORY;
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
virtual QStringList subProviders() const override;
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayerlabeling.h
Expand Up @@ -39,7 +39,7 @@ class QgsVectorLayerLabelProvider;
class CORE_EXPORT QgsAbstractVectorLayerLabeling
{
public:

//! Default constructor
QgsAbstractVectorLayerLabeling() = default;
virtual ~QgsAbstractVectorLayerLabeling() = default;

Expand All @@ -50,6 +50,7 @@ class CORE_EXPORT QgsAbstractVectorLayerLabeling
virtual QgsAbstractVectorLayerLabeling *clone() const = 0 SIP_FACTORY;

//! Factory for label provider implementation
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const SIP_SKIP { Q_UNUSED( layer ); return nullptr; }

//! Return labeling configuration as XML element
Expand Down Expand Up @@ -99,6 +100,7 @@ class CORE_EXPORT QgsVectorLayerSimpleLabeling : public QgsAbstractVectorLayerLa

virtual QString type() const override;
virtual QgsAbstractVectorLayerLabeling *clone() const override SIP_FACTORY;
//! \note not available in Python bindings
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override SIP_SKIP;
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
virtual QgsPalLayerSettings settings( const QString &providerId = QString() ) const override;
Expand Down
7 changes: 3 additions & 4 deletions tests/src/core/testqgslabelingengine.cpp
Expand Up @@ -98,10 +98,9 @@ void TestQgsLabelingEngine::cleanup()
void TestQgsLabelingEngine::setDefaultLabelParams( QgsPalLayerSettings &settings )
{
QgsTextFormat format;
QFont font( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ).family(), 12 );
format.setFont( font );
format.setSize( 12 );
format.setNamedStyle( QgsFontUtils::translateNamedStyle( "Bold" ) );
format.setFont( QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) ) );
format.setSize( 12.4 ); // TODO: why does it render nothing when point size == 12 ???
format.setNamedStyle( "Bold" );
format.setColor( QColor( 200, 0, 200 ) );
settings.setFormat( format );
}
Expand Down
29 changes: 15 additions & 14 deletions tests/src/python/test_qgspallabeling_base.py
Expand Up @@ -34,14 +34,18 @@

from qgis.core import (
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsDataSourceUri,
QgsGeometry,
QgsLabelingEngineSettings,
QgsProject,
QgsMapSettings,
QgsPalLabeling,
QgsPalLayerSettings,
QgsProviderRegistry,
QgsStringReplacementCollection,
QgsVectorLayer,
QgsVectorLayerSimpleLabeling,
QgsMultiRenderChecker,
QgsUnitTypes
)
Expand Down Expand Up @@ -273,6 +277,8 @@ def settingsDict(lyr):
for attr in dir(lyr):
if attr[0].islower() and not attr.startswith("__"):
value = getattr(lyr, attr)
if isinstance(value, (QgsGeometry, QgsStringReplacementCollection, QgsCoordinateTransform)):
continue # ignore these objects
if not isinstance(value, collections.Callable):
res[attr] = value
return res
Expand Down Expand Up @@ -392,18 +398,14 @@ def test_default_pal_disabled(self):
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
self.assertEqual(palset, '', msg)

def test_settings_enable_pal(self):
# Verify default PAL settings enable PAL labeling for layer
lyr = QgsPalLayerSettings()
lyr.writeToLayer(self.layer)
palset = self.layer.customProperty('labeling', '')
msg = '\nExpected: Empty string\nGot: {0}'.format(palset)
self.assertEqual(palset, 'pal', msg)
def test_settings_no_labeling(self):
self.layer.setLabeling(None)
self.assertEqual(None, self.layer.labeling())

def test_layer_pal_activated(self):
# Verify, via engine, that PAL labeling can be activated for layer
lyr = self.defaultLayerSettings()
lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr))
msg = '\nLayer labeling not activated, as reported by labelingEngine'
self.assertTrue(QgsPalLabeling.staticWillUseLayer(self.layer), msg)

Expand All @@ -412,14 +414,13 @@ def test_write_read_settings(self):
# load and write default test settings
lyr1 = self.defaultLayerSettings()
lyr1dict = self.settingsDict(lyr1)
# print lyr1dict
lyr1.writeToLayer(self.layer)
# print(lyr1dict)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(lyr1))

# read settings
lyr2 = QgsPalLayerSettings()
lyr2.readFromLayer(self.layer)
lyr2dict = self.settingsDict(lyr1)
# print lyr2dict
lyr2 = self.layer.labeling().settings()
lyr2dict = self.settingsDict(lyr2)
# print(lyr2dict)

msg = '\nLayer settings read not same as settings written'
self.assertDictEqual(lyr1dict, lyr2dict, msg)
Expand Down
3 changes: 2 additions & 1 deletion tests/src/python/test_qgspallabeling_canvas.py
Expand Up @@ -22,6 +22,7 @@
import sys
import os
from qgis.PyQt.QtCore import qDebug, QThreadPool
from qgis.core import QgsVectorLayerSimpleLabeling

from utilities import (
getTempfilePath,
Expand Down Expand Up @@ -67,7 +68,7 @@ def setUp(self):
self._ColorTols.clear()

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgspallabeling_composer.py
Expand Up @@ -28,7 +28,8 @@
from qgis.PyQt.QtPrintSupport import QPrinter
from qgis.PyQt.QtSvg import QSvgRenderer, QSvgGenerator

from qgis.core import QgsComposition, QgsMapSettings, QgsProject, QgsComposerMap
from qgis.core import QgsComposition, QgsMapSettings, QgsProject, QgsComposerMap, QgsVectorLayerSimpleLabeling


from utilities import (
getTempfilePath,
Expand Down Expand Up @@ -284,7 +285,7 @@ def get_composer_output(self, kind):

# noinspection PyUnusedLocal
def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
Expand Down
5 changes: 3 additions & 2 deletions tests/src/python/test_qgspallabeling_placement.py
Expand Up @@ -27,7 +27,8 @@
QgsPalLayerSettings,
QgsSingleSymbolRenderer,
QgsMarkerSymbol,
QgsProperty)
QgsProperty,
QgsVectorLayerSimpleLabeling)
from utilities import getTempfilePath, renderMapToImage, mapSettingsString

from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
Expand Down Expand Up @@ -65,7 +66,7 @@ def setUp(self):
self._MapSettings.setLabelingEngineSettings(engine_settings)

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.layer.setLabeling(QgsVectorLayerSimpleLabeling(self.lyr))

ms = self._MapSettings # class settings
settings_type = 'Class'
Expand Down
36 changes: 0 additions & 36 deletions tests/src/python/test_qgstextrenderer.py
Expand Up @@ -93,15 +93,6 @@ def testBufferGettersSetters(self):
s.setFillBufferInterior(True)
self.assertTrue(s.fillBufferInterior())

def testBufferReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBufferSettings()
s.writeToLayer(layer)
t = QgsTextBufferSettings()
t.readFromLayer(layer)
self.checkBufferSettings(t)

def testBufferReadWriteXml(self):
"""test saving and restoring state of a buffer to xml"""
doc = QDomDocument("testdoc")
Expand Down Expand Up @@ -190,15 +181,6 @@ def testBackgroundCopy(self):
s3 = QgsTextBackgroundSettings(s)
self.checkBackgroundSettings(s3)

def testBackgroundReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createBackgroundSettings()
s.writeToLayer(layer)
t = QgsTextBackgroundSettings()
t.readFromLayer(layer)
self.checkBackgroundSettings(t)

def testBackgroundReadWriteXml(self):
"""test saving and restoring state of a background to xml"""
doc = QDomDocument("testdoc")
Expand Down Expand Up @@ -272,15 +254,6 @@ def testShadowCopy(self):
s3 = QgsTextShadowSettings(s)
self.checkShadowSettings(s3)

def testShadowReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createShadowSettings()
s.writeToLayer(layer)
t = QgsTextShadowSettings()
t.readFromLayer(layer)
self.checkShadowSettings(t)

def testShadowReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")
Expand Down Expand Up @@ -340,15 +313,6 @@ def testFormatCopy(self):
s3 = QgsTextFormat(s)
self.checkTextFormat(s3)

def testFormatReadWriteLayer(self):
"""test writing and retrieving settings from a layer"""
layer = createEmptyLayer()
s = self.createFormatSettings()
s.writeToLayer(layer)
t = QgsTextFormat()
t.readFromLayer(layer)
self.checkTextFormat(t)

def testFormatReadWriteXml(self):
"""test saving and restoring state of a shadow to xml"""
doc = QDomDocument("testdoc")
Expand Down

0 comments on commit bfdc84f

Please sign in to comment.