Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jan 13, 2017
1 parent 8de606a commit a2de2ae
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ distances-aligned.csv
i18n/*.qm
DistanceMatrixToCoords.zip
i18n/latest_run

.coverage
4 changes: 2 additions & 2 deletions ghini_tree_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ def _sink(self, index):
"""
while True:
maxleafindex = (index+1)*2-1
maxleafindex = (index + 1) * 2 - 1
try:
if self.heap[maxleafindex]['prio'] < self.heap[
maxleafindex+1]['prio']:
maxleafindex + 1]['prio']:
maxleafindex += 1
except IndexError:
pass
Expand Down
2 changes: 1 addition & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# import qgis libs so that ve set the correct sip api version
import qgis # pylint: disable=W0611 # NOQA
import qgis # pylint: disable=W0611 # NOQA
18 changes: 9 additions & 9 deletions test/qgis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Copyright (c) 2014 Tim Sutton, [email protected]
"""
import logging
from PyQt4.QtCore import QObject, pyqtSlot, pyqtSignal
from qgis.core import QgsMapLayerRegistry
from qgis.gui import QgsMapCanvasLayer

__author__ = '[email protected]'
__revision__ = '$Format:%H$'
Expand All @@ -23,14 +27,10 @@
'Copyright (c) 2014 Tim Sutton, [email protected]'
)

import logging
from PyQt4.QtCore import QObject, pyqtSlot, pyqtSignal
from qgis.core import QgsMapLayerRegistry
from qgis.gui import QgsMapCanvasLayer
LOGGER = logging.getLogger('QGIS')


#noinspection PyMethodMayBeStatic,PyPep8Naming
# noinspection PyMethodMayBeStatic,PyPep8Naming
class QgisInterface(QObject):
"""Class to expose QGIS objects and functions to plugins.
Expand Down Expand Up @@ -67,9 +67,9 @@ def addLayers(self, layers):
.. note:: The QgsInterface api does not include this method,
it is added here as a helper to facilitate testing.
"""
#LOGGER.debug('addLayers called on qgis_interface')
#LOGGER.debug('Number of layers being added: %s' % len(layers))
#LOGGER.debug('Layer Count Before: %s' % len(self.canvas.layers()))
# LOGGER.debug('addLayers called on qgis_interface')
# LOGGER.debug('Number of layers being added: %s' % len(layers))
# LOGGER.debug('Layer Count Before: %s' % len(self.canvas.layers()))
current_layers = self.canvas.layers()
final_layers = []
for layer in current_layers:
Expand All @@ -78,7 +78,7 @@ def addLayers(self, layers):
final_layers.append(QgsMapCanvasLayer(layer))

self.canvas.setLayerSet(final_layers)
#LOGGER.debug('Layer Count After: %s' % len(self.canvas.layers()))
# LOGGER.debug('Layer Count After: %s' % len(self.canvas.layers()))

@pyqtSlot('QgsMapLayer')
def addLayer(self, layer):
Expand Down
13 changes: 5 additions & 8 deletions test/test_ghini_tree_position_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
"""

__author__ = '[email protected]'
__date__ = '2017-01-04'
__copyright__ = 'Copyright 2017, Mario Frasca'

import unittest

from PyQt4.QtGui import QDialogButtonBox, QDialog

from ghini_tree_position_dialog import DistanceMatrixToCoordsDialog

from utilities import get_qgis_app

__author__ = '[email protected]'
__date__ = '2017-01-04'
__copyright__ = 'Copyright 2017, Mario Frasca'

QGIS_APP = get_qgis_app()


Expand Down Expand Up @@ -52,4 +50,3 @@ def test_dialog_cancel(self):
suite = unittest.makeSuite(DistanceMatrixToCoordsDialogTest)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)

44 changes: 26 additions & 18 deletions test/test_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

from ghini_tree_position import Heap


class HeapTest(unittest.TestCase):
def test_init(self):
i = Heap([{'prio':1},{'prio':2},{'prio':3}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}])
print(dir(self))
self.assertEquals(i.priorities(), [3, 1, 2])
i = Heap([{'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}])
self.assertEquals(i.priorities(), [5, 4, 2, 1, 3])
i = Heap([{'prio':1},{'prio':3},{'prio':2},{'prio':4},{'prio':5}])
i = Heap([{'prio': 1}, {'prio': 3}, {'prio': 2}, {'prio': 4},
{'prio': 5}])
self.assertEquals(i.priorities(), [5, 4, 2, 1, 3])
i = Heap([{'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7}])
self.assertEquals(i.priorities(), [7, 4, 5, 1, 3, 2])

def test_push(self):

i = Heap([{'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7}])
i.push({'prio': 8})
self.assertEquals(i.pop(), {'prio': 8})
i.push({'prio': 6})
Expand All @@ -25,7 +30,8 @@ def test_push(self):

def test_pop(self):

i = Heap([{'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7}])
self.assertEquals(i.pop(), {'prio': 7})
self.assertEquals(i.pop(), {'prio': 5})
self.assertEquals(i.pop(), {'prio': 4})
Expand All @@ -34,7 +40,8 @@ def test_pop(self):
self.assertEquals(i.pop(), {'prio': 1})
self.assertEquals(len(i.priorities()), 0)

a, b, c, d, e, f = ({'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7})
a, b, c, d, e, f = ({'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7})
i = Heap([f, e, b, c, d, a])
self.assertEquals(i.priorities(), [7, 5, 2, 3, 4, 1])
self.assertEquals(i.pop(), {'prio': 7})
Expand All @@ -44,17 +51,19 @@ def test_pop(self):

def test_reprioritize(self):

a, b, c, d, e, f = ({'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7})
a, b, c, d, e, f = ({'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7})
i = Heap([a, b, c, d, e, f])

## nothing happens if the priority change is zero
# nothing happens if the priority change is zero
self.assertEquals(i.priorities(), [7, 4, 5, 1, 3, 2])
i.reprioritize(a, 0)
self.assertEquals(i.priorities(), [7, 4, 5, 1, 3, 2])

## the priority change default value is the positive unit. you specify
## the object of which the priority has to be altered.
a, b, c, d, e, f = ({'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7})
# the priority change default value is the positive unit. you specify
# the object of which the priority has to be altered.
a, b, c, d, e, f = ({'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7})
i = Heap([a, b, c, d, e, f])
self.assertEquals(i.priorities(), [7, 4, 5, 1, 3, 2])
i.reprioritize(a)
Expand All @@ -67,25 +76,24 @@ def test_reprioritize(self):
self.assertEquals(i.priorities(), [7, 5, 5, 4, 3, 2])
self.assertEquals(a, {'heappos': 1, 'prio': 5})

## you can give any value for the desired priority change.
a, b, c, d, e, f = ({'prio':1},{'prio':2},{'prio':3},{'prio':4},{'prio':5},{'prio':7})
# you can give any value for the desired priority change.
a, b, c, d, e, f = ({'prio': 1}, {'prio': 2}, {'prio': 3}, {'prio': 4},
{'prio': 5}, {'prio': 7})
i = Heap([a, b, c, d, e, f])
self.assertEquals(i.priorities(), [7, 4, 5, 1, 3, 2])
i.reprioritize(c, 8)
self.assertEquals(i.priorities(), [11, 7, 5, 1, 4, 2])
i.reprioritize(e, 15)
self.assertEquals(i.priorities(), [20, 7, 11, 1, 4, 2])

## a negative priority change will sink the object into the heap
# a negative priority change will sink the object into the heap
i.reprioritize(e, -20)
self.assertEquals(i.priorities(), [11, 7, 2, 1, 4, 0])
i.reprioritize(c, -12)
self.assertEquals(i.priorities(), [7, 4, 2, 1, -1, 0])

def test_swap(self):
i = Heap([{'prio':1},{'prio':2},{'prio':3}])
i = Heap([{'prio': 1}, {'prio': 2}, {'prio': 3}])
self.assertEquals(i.priorities(), [3, 1, 2])
i._swap(0, 1)
self.assertEquals(i.priorities(), [1, 3, 2])


10 changes: 5 additions & 5 deletions test/test_init.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# coding=utf-8
"""Tests QGIS plugin init."""

import os
import unittest
import logging
import ConfigParser

__author__ = 'Tim Sutton <[email protected]>'
__revision__ = '$Format:%H$'
__date__ = '17/10/2010'
__license__ = "GPL"
__copyright__ = 'Copyright 2012, Australia Indonesia Facility for '
__copyright__ += 'Disaster Reduction'

import os
import unittest
import logging
import ConfigParser

LOGGER = logging.getLogger('QGIS')


Expand Down
11 changes: 6 additions & 5 deletions test/test_qgis_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
(at your option) any later version.
"""
__author__ = '[email protected]'
__date__ = '20/01/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')

import os
import unittest
from qgis.core import (
Expand All @@ -21,6 +16,12 @@
QgsRasterLayer)

from utilities import get_qgis_app

__author__ = '[email protected]'
__date__ = '20/01/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')

QGIS_APP = get_qgis_app()


Expand Down
10 changes: 3 additions & 7 deletions test/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"""

__author__ = '[email protected]'
__date__ = '2017-01-04'
__copyright__ = 'Copyright 2017, Mario Frasca'

import unittest

from PyQt4.QtGui import QIcon

__author__ = '[email protected]'
__date__ = '2017-01-04'
__copyright__ = 'Copyright 2017, Mario Frasca'


class DistanceMatrixToCoordsDialogTest(unittest.TestCase):
Expand All @@ -39,6 +38,3 @@ def test_icon_png(self):
suite = unittest.makeSuite(DistanceMatrixToCoordsResourcesTest)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)



7 changes: 3 additions & 4 deletions test/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
"""
from utilities import get_qgis_app
import unittest
import os
from PyQt4.QtCore import QCoreApplication, QTranslator

__author__ = '[email protected]'
__date__ = '12/10/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
import unittest
import os

from PyQt4.QtCore import QCoreApplication, QTranslator

QGIS_APP = get_qgis_app()

Expand Down
13 changes: 7 additions & 6 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ghini_tree_position import almost_parallel, normalize


class UtilsTest(unittest.TestCase):
def test_normalize_null(self):
null_vector = (0, 0, 0)
Expand All @@ -13,28 +14,28 @@ def test_normalize_not_null(self):
self.assertFalse(any(normalize(vector) - expected))

def test_almost_parallel_vectors_not(self):
u, v = [1,0,0], [0,1,0]
u, v = [1, 0, 0], [0, 1, 0]
self.assertFalse(almost_parallel(u, v))

def test_almost_parallel_matrix_not(self):
import numpy as np
A = np.array([[1,0,0],[0,1,0]])
A = np.array([[1, 0, 0], [0, 1, 0]])
self.assertFalse(almost_parallel(A))

def test_almost_parallel_vectors_precisely(self):
import numpy as np
A = np.array([[1,1,0],[2,2,0]])
A = np.array([[1, 1, 0], [2, 2, 0]])
self.assertTrue(almost_parallel(A))

def test_almost_parallel_matrix_almost(self):
import numpy as np
A = np.array([[1,0,0],[1999,1,-1]])
A = np.array([[1, 0, 0], [1999, 1, -1]])
self.assertTrue(almost_parallel(A))

def test_almost_parallel_vectors_precisely(self):
u, v = [1,1,0],[2,2,0]
u, v = [1, 1, 0], [2, 2, 0]
self.assertTrue(almost_parallel(u, v))

def test_almost_parallel_vectors_almost(self):
u, v = [1,0,0], [1999,1,-1]
u, v = [1, 0, 0], [1999, 1, -1]
self.assertTrue(almost_parallel(u, v))
8 changes: 4 additions & 4 deletions test/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_qgis_app():

if QGIS_APP is None:
gui_flag = True # All test will run qgis in gui mode
#noinspection PyPep8Naming
# noinspection PyPep8Naming
QGIS_APP = QgsApplication(sys.argv, gui_flag)
# Make sure QGIS_PREFIX_PATH is set in your env if needed!
QGIS_APP.initQgis()
Expand All @@ -43,19 +43,19 @@ def get_qgis_app():

global PARENT # pylint: disable=W0603
if PARENT is None:
#noinspection PyPep8Naming
# noinspection PyPep8Naming
PARENT = QtGui.QWidget()

global CANVAS # pylint: disable=W0603
if CANVAS is None:
#noinspection PyPep8Naming
# noinspection PyPep8Naming
CANVAS = QgsMapCanvas(PARENT)
CANVAS.resize(QtCore.QSize(400, 400))

global IFACE # pylint: disable=W0603
if IFACE is None:
# QgisInterface is a stub implementation of the QGIS plugin interface
#noinspection PyPep8Naming
# noinspection PyPep8Naming
IFACE = QgisInterface(CANVAS)

return QGIS_APP, CANVAS, IFACE, PARENT

0 comments on commit a2de2ae

Please sign in to comment.