Skip to content
Permalink
Browse files
Python formatting updates
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 65c2e5a commit 9124100fb698912b01f678bf5598c0225f568b8f
@@ -89,8 +89,8 @@ def defineCharacteristics(self):
optional=True,
metadata={'widget_wrapper': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}))
self.addParameter(ParameterSelection(self.RTYPE,
self.tr('Output raster type'),
self.TYPE, 5))
self.tr('Output raster type'),
self.TYPE, 5))

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Clipped (mask)')))

@@ -140,8 +140,8 @@ def _rectangleGrid(self, writer, width, height, originX, originY,
hSpacing, vSpacing, hOverlay, vOverlay, feedback):
ft = QgsFeature()

columns = int(math.ceil(float(width) / (hSpacing-hOverlay)))
rows = int(math.ceil(float(height) / (vSpacing-vOverlay)))
columns = int(math.ceil(float(width) / (hSpacing - hOverlay)))
rows = int(math.ceil(float(height) / (vSpacing - vOverlay)))

cells = rows * columns
count_update = cells * 0.05
@@ -193,13 +193,13 @@ def _diamondGrid(self, writer, width, height, originX, originY,
count = 0

for col in range(columns):
x = originX - (col * halfHOverlay)
x = originX - (col * halfHOverlay)
x1 = x + ((col + 0) * halfHSpacing)
x2 = x + ((col + 1) * halfHSpacing)
x3 = x + ((col + 2) * halfHSpacing)

for row in range(rows):
y = originY + (row * halfVOverlay)
y = originY + (row * halfVOverlay)
if (col % 2) == 0:
y1 = y - (((row * 2) + 0) * halfVSpacing)
y2 = y - (((row * 2) + 1) * halfVSpacing)
@@ -236,7 +236,7 @@ def requestFinished(self):
reply.deleteLater()
self.txtHelp.setHtml(html)

def getAvailableDependencies(self): #spellok
def getAvailableDependencies(self): # spellok
if self._algName is None:
dependent = []
else:
@@ -248,7 +248,7 @@ def getAvailableDependencies(self): #spellok
return opts

def getDependenciesPanel(self):
return MultipleInputPanel([alg.description for alg in self.getAvailableDependencies()]) #spellok
return MultipleInputPanel([alg.description for alg in self.getAvailableDependencies()]) # spellok

def showAdvancedParametersClicked(self):
self.showAdvanced = not self.showAdvanced
@@ -318,7 +318,7 @@ def setPreviousValues(self):
self.valueItems[name].setText(out.description)

selected = []
dependencies = self.getAvailableDependencies() #spellok
dependencies = self.getAvailableDependencies() # spellok
for idx, dependency in enumerate(dependencies):
if dependency.name in alg.dependencies:
selected.append(idx)
@@ -345,9 +345,9 @@ def createAlgorithm(self):
alg.outputs[output.name] = ModelerOutput(name)

selectedOptions = self.dependenciesPanel.selectedoptions
availableDependencies = self.getAvailableDependencies() #spellok
availableDependencies = self.getAvailableDependencies() # spellok
for selected in selectedOptions:
alg.dependencies.append(availableDependencies[selected].name) #spellok
alg.dependencies.append(availableDependencies[selected].name) # spellok

self._alg.processBeforeAddingToModeler(alg, self.model)
return alg
@@ -631,7 +631,7 @@
"QgsZipItem": ["QgsZipItem(QgsDataItem *parent, const QString &name, const QString &filePath, const QString &path)", "itemFromPath(QgsDataItem *parent, QString path, QString name)", "getZipFileList()", "QgsZipItem(QgsDataItem *parent, const QString &name, const QString &path)", "iconZip()", "vsiPrefix(const QString &uri)"],
"NormVecDecorator": ["NormVecDecorator(Triangulation *tin)"],
"QgsVectorLayerJoinBuffer": ["vectorJoins() const ", "QgsVectorLayerJoinBuffer(QgsVectorLayer *layer=nullptr)"],
"pal::Pal": ["solveProblem(Problem *prob, bool displayAll)", "extractProblem(double bbox[4])", "FnIsCancelled)(void *ctx)"], #spellok
"pal::Pal": ["solveProblem(Problem *prob, bool displayAll)", "extractProblem(double bbox[4])", "FnIsCancelled)(void *ctx)"], # spellok
"QgsSearchWidgetWrapper": ["setExpression(QString value)=0"],
"QgsRasterFillSymbolLayer": ["create(const QgsStringMap &properties=QgsStringMap())", "QgsRasterFillSymbolLayer(const QString &imageFilePath=QString())", "FillCoordinateMode"],
"QgsExpression::NodeInOperator": ["NodeInOperator(Node *node, NodeList *list, bool notin=false)", "node() const ", "isNotIn() const ", "list() const "],
@@ -142,8 +142,8 @@ def authorizedLayerAttributes(self, layer, attributes):
if not self._active:
return super(RestrictedAccessControl, self).authorizedLayerAttributes(layer, attributes)

if "colour" in attributes: #spellok
attributes.remove("colour") #spellok
if "colour" in attributes: # spellok
attributes.remove("colour") # spellok
return attributes

def allowToEdit(self, layer, feature):
@@ -378,18 +378,18 @@ def test_wms_getfeatureinfo_hello(self):
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeatureInfo\n%s" % response)
self.assertTrue(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
"No color in result of GetFeatureInfo\n%s" % response)

response, headers = self._get_restricted(query_string)
self.assertTrue(
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeatureInfo\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
"Unexpected color in result of GetFeatureInfo\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, # spellok
"Unexpected color NULL in result of GetFeatureInfo\n%s" % response)

def test_wms_getfeatureinfo_hello2(self):
@@ -530,18 +530,18 @@ def test_wfs_getfeature_hello(self):
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeature\n%s" % response)
self.assertTrue(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
"No color in result of GetFeature\n%s" % response)

response, headers = self._post_restricted(data)
self.assertTrue(
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"No result in GetFeature\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>red</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>red</qgs:colour>") != -1, # spellok
"Unexpected color in result of GetFeature\n%s" % response)
self.assertFalse(
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, #spellok
str(response).find("<qgs:colour>NULL</qgs:colour>") != -1, # spellok
"Unexpected color NULL in result of GetFeature\n%s" % response)

def test_wfs_getfeature_hello2(self):
@@ -580,7 +580,7 @@ def test_wfs_getfeature_country(self):
response, headers = self._post_restricted(data)
self.assertFalse(
str(response).find("<qgs:pk>1</qgs:pk>") != -1,
"Unexpeced result in GetFeatureInfo\n%s" % response) #spellok
"Unexpeced result in GetFeatureInfo\n%s" % response) # spellok


# # WCS # # WCS # # WCS # #
@@ -5,50 +5,50 @@
from qgis.testing import unittest
from qgis.core import QgsApplication
from qgis.server import (QgsServer,
QgsServiceRegistry,
QgsServiceRegistry,
QgsService,
QgsServerRequest,
QgsServerResponse)

from utilities import unitTestDataPath


class Response(QgsServerResponse):

def __init__( self ):
def __init__(self):
QgsServerResponse.__init__(self)
self._buffer = QBuffer()
self._buffer.open(QIODevice.ReadWrite)


def setReturnCode( self, code ):
def setReturnCode(self, code):
pass

def setHeader( self, key, val ):
def setHeader(self, key, val):
pass

def sendError( self, code, message ):
def sendError(self, code, message):
pass

def io(self):
return self._buffer


class MyService(QgsService):

def __init__(self, name, version, response):
QgsService.__init__(self)
self._response = response
self._name = name
self._version = version
self._name = name
self._version = version

def name(self):
return self._name

def version(self):
return self._version

def executeRequest( self, request, response ):
def executeRequest(self, request, response):

url = request.url()

response.setReturnCode(201)
@@ -65,7 +65,7 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
cls.app.exitQgis()
cls.app.exitQgis()

def setUp(self):
"""Create the server instance"""
@@ -82,16 +82,15 @@ def setUp(self):
except KeyError:
pass
self.server = QgsServer()

def test_modules(self):
""" Tests that modules are loaded """

# Check that our 'SampleService is registered
iface = self.server.serverInterface()
iface = self.server.serverInterface()
service = iface.serviceRegistry().getService('SampleService')

self.assertIsNotNone(service)

self.assertIsNotNone(service)


if __name__ == '__main__':
@@ -2,31 +2,31 @@
"""
from qgis.PyQt.QtCore import QBuffer, QIODevice, QTextStream
from qgis.testing import unittest
from qgis.server import (QgsServiceRegistry,
from qgis.server import (QgsServiceRegistry,
QgsService,
QgsServerRequest,
QgsServerResponse)

from qgis.core import QgsApplication


class Response(QgsServerResponse):

def __init__( self ):
def __init__(self):
QgsServerResponse.__init__(self)
self._buffer = QBuffer()
self._buffer.open(QIODevice.ReadWrite)


def setReturnCode( self, code ):
def setReturnCode(self, code):
pass

def setHeader( self, key, val ):
def setHeader(self, key, val):
pass

def clearHeader( self, key ):
def clearHeader(self, key):
pass

def sendError( self, code, message ):
def sendError(self, code, message):
pass

def io(self):
@@ -43,21 +43,21 @@ def clear(self):


class MyService(QgsService):

def __init__(self, name, version, response):
QgsService.__init__(self)
self._response = response
self._name = name
self._version = version
self._name = name
self._version = version

def name(self):
return self._name

def version(self):
return self._version

def executeRequest( self, request, response ):
def executeRequest(self, request, response):

url = request.url()

response.setReturnCode(201)
@@ -82,29 +82,29 @@ def test_register(self):

myserv = MyService("TEST", "1.0", "Hello world")

reg.registerService( myserv )
reg.registerService(myserv)

# Retrieve service
request = QgsServerRequest("http://DoStufff", QgsServerRequest.GetMethod)
request = QgsServerRequest("http://DoStufff", QgsServerRequest.GetMethod)
response = Response()

service = reg.getService("TEST")
if service:
service.executeRequest(request, response)
io = response.io();

io = response.io()
io.seek(0)

self.assertEqual(QTextStream(io).readLine(), "Hello world")

def test_0_version_registration(self):

reg = QgsServiceRegistry()
reg = QgsServiceRegistry()
myserv1 = MyService("TEST", "1.1", "Hello")
myserv2 = MyService("TEST", "1.0", "Hello")
reg.registerService( myserv1 )
reg.registerService( myserv2)

reg.registerService(myserv1)
reg.registerService(myserv2)

service = reg.getService("TEST")
self.assertIsNotNone(service)
@@ -118,10 +118,9 @@ def test_0_version_registration(self):
self.assertIsNotNone(service)
self.assertEqual(service.version(), "1.0")


def test_1_unregister_services(self):

reg = QgsServiceRegistry()
reg = QgsServiceRegistry()
serv1 = MyService("TEST", "1.0a", "Hello")
serv2 = MyService("TEST", "1.0b", "Hello")
serv3 = MyService("TEST", "1.0c", "Hello")
@@ -132,21 +131,21 @@ def test_1_unregister_services(self):

# Check we get the default version
service = reg.getService("TEST")
self.assertEqual( service.version(), "1.0a" )
self.assertEqual(service.version(), "1.0a")

# Remove one service
removed = reg.unregisterService("TEST", "1.0a")
self.assertEqual( removed, 1 )
self.assertEqual(removed, 1)

# Check that we get the highest version
service = reg.getService("TEST")
self.assertEqual( service.version(), "1.0c" )
# Remove all services
self.assertEqual(service.version(), "1.0c")

# Remove all services
removed = reg.unregisterService("TEST")
self.assertEqual( removed, 2 )
self.assertEqual(removed, 2)

# Check that there is no more services available
# Check that there is no more services available
service = reg.getService("TEST")
self.assertIsNone(service)

0 comments on commit 9124100

Please sign in to comment.