Skip to content
Permalink
Browse files

Condense labeling test class inheritance and set up local server para…

…ms from map settings
  • Loading branch information
dakcarto committed Mar 6, 2014
1 parent 53cfa9e commit 803bc296da941ad2bd653766704fc3dd4855bc6a
@@ -126,8 +126,11 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
"""Run after all tests"""
pass
# cls.removeAllLayers()

def setUp(self):
"""Run before each test."""
TestQgsPalLabeling.setDefaultEngineSettings()
self.lyr = self.defaultLayerSettings()

@classmethod
def setDefaultEngineSettings(cls):
@@ -141,6 +144,18 @@ def removeAllLayers(cls):
cls._MapRegistry.removeAllMapLayers()
cls._MapSettings.setLayers([])

@classmethod
def removeMapLayer(cls, layer):
if layer is None:
return
lyr_id = layer.id()
cls._MapRegistry.removeMapLayer(lyr_id)
ms_layers = cls._MapSettings.layers()
""":type: QStringList"""
if ms_layers.contains(lyr_id):
ms_layers.removeAt(ms_layers.indexOf(lyr_id))
cls._MapSettings.setLayers(ms_layers)

@classmethod
def getTestFont(cls):
return QFont(cls._TestFont)
@@ -379,6 +394,10 @@ def renderCheck(self, mismatch=0, imgpath='', grpprefix=''):
msg = '\nRender check failed for "{0}"'.format(self._Test)
return res, msg

def checkTest(self, **kwargs):
"""Intended to be overridden in subclasses"""
pass


class TestPALConfig(TestQgsPalLabeling):

@@ -39,34 +39,48 @@
)


class TestCanvasPoint(TestQgsPalLabeling, TestPointBase):
class TestCanvasBase(TestQgsPalLabeling):

layer = None
""":type: QgsVectorLayer"""

@classmethod
def setUpClass(cls):
if not cls._BaseSetup:
TestQgsPalLabeling.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('point')

@classmethod
def tearDownClass(cls):
TestQgsPalLabeling.tearDownClass()
cls._MapRegistry.removeMapLayer(cls.layer.id())
cls.removeMapLayer(cls.layer)
cls.layer = None

def setUp(self):
"""Run before each test."""
self.configTest('pal_canvas', 'sp')
TestQgsPalLabeling.setDefaultEngineSettings()
self.lyr = self.defaultLayerSettings()
super(TestCanvasBase, self).setUp()

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
self.saveControlImage()
self.assertTrue(*self.renderCheck())


class TestCanvasBasePoint(TestCanvasBase):

@classmethod
def setUpClass(cls):
TestCanvasBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('point')


class TestCanvasPoint(TestCanvasBasePoint, TestPointBase):

def setUp(self):
"""Run before each test."""
super(TestCanvasPoint, self).setUp()
self.configTest('pal_canvas', 'sp')


if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# SEE: test_qgspallabeling_tests.suiteTests() to define suite
@@ -76,19 +76,18 @@ def setUpClass(cls):
TestQgsPalLabeling.loadFeatureLayer('background', True)
cls._CheckMismatch = 0 # mismatch expected for crosscheck
cls._TestImage = ''
cls._TestKind = '' # img|svg|pdf
cls._TestKind = 0 # OutputKind.(Img|Svg|Pdf)

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
TestQgsPalLabeling.tearDownClass()
cls._MapRegistry.removeMapLayer(cls.layer.id())
cls.removeMapLayer(cls.layer)
cls.layer = None

def setUp(self):
"""Run before each test."""
TestQgsPalLabeling.setDefaultEngineSettings()
self.lyr = self.defaultLayerSettings()
super(TestComposerBase, self).setUp()
self._TestImage = ''
# ensure per test map settings stay encapsulated
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
@@ -59,6 +59,9 @@ class TestServerBase(TestQgsPalLabeling):
_TestProj = None
""":type: QgsProject"""
_TestProjName = ''
layer = None
""":type: QgsVectorLayer"""
params = dict()

@classmethod
def setUpClass(cls):
@@ -86,8 +89,10 @@ def setUpClass(cls):
def tearDownClass(cls):
"""Run after all tests"""
TestQgsPalLabeling.tearDownClass()
cls.removeMapLayer(cls.layer)
cls.layer = None
# layers removed, save empty project file
# cls._TestProj.write()
cls._TestProj.write()
if "PAL_SERVER_TEMP" in os.environ:
MAPSERV.stop_processes()
MAPSERV.open_temp_dir()
@@ -99,64 +104,47 @@ def setUp(self):
# web server stays up across all tests
# MAPSERV.fcgi_server_process().stop()
# self.deleteCache()
super(TestServerBase, self).setUp()
self._TestImage = ''
# ensure per test map settings stay encapsulated
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)

# noinspection PyPep8Naming
def deleteCache(self):
def delete_cache(self):
for item in os.listdir(self._CacheDir):
shutil.rmtree(os.path.join(self._CacheDir, item),
ignore_errors=True)

# noinspection PyPep8Naming
def defaultWmsParams(self, layername):
return {
def get_wms_params(self):
ms = self._TestMapSettings
osize = ms.outputSize()
dpi = str(ms.outputDpi())
lyrs = [str(self._MapRegistry.mapLayer(i).name()) for i in ms.layers()]
lyrs.reverse()
params = {
'SERVICE': 'WMS',
'VERSION': '1.3.0',
'REQUEST': 'GetMap',
'MAP': self._TestProjName,
# layer stacking order for rendering: bottom,to,top
'LAYERS': ['background', str(layername).strip()], # or 'name,name'
'LAYERS': lyrs, # or 'name,name'
'STYLES': ',',
# authid str or QgsCoordinateReferenceSystem obj
'CRS': 'EPSG:32613', # self._CRS
'BBOX': '606510,4823130,612510,4827130', # self.aoiExtent(),
'CRS': str(ms.destinationCrs().authid()),
# self.aoiExtent(),
'BBOX': str(ms.extent().toString(True).replace(' : ', ',')),
'FORMAT': 'image/png', # or: 'image/png; mode=8bit'
'WIDTH': '600',
'HEIGHT': '400',
'DPI': '72',
'MAP_RESOLUTION': '72',
'FORMAT_OPTIONS': 'dpi:72',
'WIDTH': str(osize.width()),
'HEIGHT': str(osize.height()),
'DPI': dpi,
'MAP_RESOLUTION': dpi,
'FORMAT_OPTIONS': 'dpi:{0}'.format(dpi),
'TRANSPARENT': 'FALSE',
'IgnoreGetMapUrl': '1'
}


class TestServerPoint(TestServerBase, TestPointBase):

layer = None
""":type: QgsVectorLayer"""

@classmethod
def setUpClass(cls):
TestServerBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('point')

@classmethod
def tearDownClass(cls):
TestServerBase.tearDownClass()
cls._MapRegistry.removeMapLayer(cls.layer.id())
cls.layer = None

def setUp(self):
"""Run before each test."""
self.configTest('pal_server', 'sp')
TestQgsPalLabeling.setDefaultEngineSettings()
self.lyr = self.defaultLayerSettings()
self.params = self.defaultWmsParams('point')
self._TestImage = ''

def tearDown(self):
"""Run after each test."""
pass
print params
return params

def checkTest(self, **kwargs):
self.lyr.writeToLayer(self.layer)
@@ -174,7 +162,27 @@ def checkTest(self, **kwargs):
imgpath=self._TestImage))


class TestServerVsCanvasPoint(TestServerPoint):
class TestServerBasePoint(TestServerBase):

@classmethod
def setUpClass(cls):
TestServerBase.setUpClass()
cls.layer = TestQgsPalLabeling.loadFeatureLayer('point')

def setUp(self):
super(TestServerBasePoint, self).setUp()
# self._TestMapSettings defines the params
self.params = self.get_wms_params()


class TestServerPoint(TestServerBasePoint, TestPointBase):

def setUp(self):
super(TestServerPoint, self).setUp()
self.configTest('pal_server', 'sp')


class TestServerVsCanvasPoint(TestServerBasePoint, TestPointBase):

def setUp(self):
super(TestServerVsCanvasPoint, self).setUp()
@@ -41,10 +41,6 @@ def __init__(self):
self._Canvas = None
""":type: QgsMapCanvas"""

def checkTest(self, **kwargs):
"""Intended to be overridden in subclasses"""
pass

def test_default_label(self):
# Default label placement, with text size in points
self.checkTest()

0 comments on commit 803bc29

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