From a2de2ae4dcd49208ced4edb628a6b2ff63f24c75 Mon Sep 17 00:00:00 2001 From: Mario Frasca Date: Fri, 13 Jan 2017 10:34:57 -0500 Subject: [PATCH] pep8 --- .gitignore | 2 ++ ghini_tree_position.py | 4 +-- test/__init__.py | 2 +- test/qgis_interface.py | 18 +++++----- test/test_ghini_tree_position_dialog.py | 13 +++----- test/test_heap.py | 44 +++++++++++++++---------- test/test_init.py | 10 +++--- test/test_qgis_environment.py | 11 ++++--- test/test_resources.py | 10 ++---- test/test_translations.py | 7 ++-- test/test_utils.py | 13 ++++---- test/utilities.py | 8 ++--- 12 files changed, 73 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index 721c2b8..d2caed8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ distances-aligned.csv i18n/*.qm DistanceMatrixToCoords.zip i18n/latest_run + +.coverage \ No newline at end of file diff --git a/ghini_tree_position.py b/ghini_tree_position.py index 3d8c157..129941c 100644 --- a/ghini_tree_position.py +++ b/ghini_tree_position.py @@ -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 diff --git a/test/__init__.py b/test/__init__.py index 8feeb0b..4b0c092 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,2 +1,2 @@ # import qgis libs so that ve set the correct sip api version -import qgis # pylint: disable=W0611 # NOQA \ No newline at end of file +import qgis # pylint: disable=W0611 # NOQA diff --git a/test/qgis_interface.py b/test/qgis_interface.py index 607c100..1cdfa1d 100644 --- a/test/qgis_interface.py +++ b/test/qgis_interface.py @@ -13,6 +13,10 @@ Copyright (c) 2014 Tim Sutton, tim@linfiniti.com """ +import logging +from PyQt4.QtCore import QObject, pyqtSlot, pyqtSignal +from qgis.core import QgsMapLayerRegistry +from qgis.gui import QgsMapCanvasLayer __author__ = 'tim@linfiniti.com' __revision__ = '$Format:%H$' @@ -23,14 +27,10 @@ 'Copyright (c) 2014 Tim Sutton, tim@linfiniti.com' ) -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. @@ -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: @@ -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): diff --git a/test/test_ghini_tree_position_dialog.py b/test/test_ghini_tree_position_dialog.py index d10d175..6b198c7 100644 --- a/test/test_ghini_tree_position_dialog.py +++ b/test/test_ghini_tree_position_dialog.py @@ -8,17 +8,15 @@ """ -__author__ = 'mario@anche.no' -__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__ = 'mario@anche.no' +__date__ = '2017-01-04' +__copyright__ = 'Copyright 2017, Mario Frasca' + QGIS_APP = get_qgis_app() @@ -52,4 +50,3 @@ def test_dialog_cancel(self): suite = unittest.makeSuite(DistanceMatrixToCoordsDialogTest) runner = unittest.TextTestRunner(verbosity=2) runner.run(suite) - diff --git a/test/test_heap.py b/test/test_heap.py index 79abab1..73b0c20 100644 --- a/test/test_heap.py +++ b/test/test_heap.py @@ -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}) @@ -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}) @@ -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}) @@ -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) @@ -67,8 +76,9 @@ 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) @@ -76,16 +86,14 @@ def test_reprioritize(self): 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]) - - diff --git a/test/test_init.py b/test/test_init.py index 923ce83..86bc568 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -1,6 +1,11 @@ # coding=utf-8 """Tests QGIS plugin init.""" +import os +import unittest +import logging +import ConfigParser + __author__ = 'Tim Sutton ' __revision__ = '$Format:%H$' __date__ = '17/10/2010' @@ -8,11 +13,6 @@ __copyright__ = 'Copyright 2012, Australia Indonesia Facility for ' __copyright__ += 'Disaster Reduction' -import os -import unittest -import logging -import ConfigParser - LOGGER = logging.getLogger('QGIS') diff --git a/test/test_qgis_environment.py b/test/test_qgis_environment.py index 8372c55..6ae5645 100644 --- a/test/test_qgis_environment.py +++ b/test/test_qgis_environment.py @@ -8,11 +8,6 @@ (at your option) any later version. """ -__author__ = 'tim@linfiniti.com' -__date__ = '20/01/2011' -__copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' - 'Disaster Reduction') - import os import unittest from qgis.core import ( @@ -21,6 +16,12 @@ QgsRasterLayer) from utilities import get_qgis_app + +__author__ = 'tim@linfiniti.com' +__date__ = '20/01/2011' +__copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' + 'Disaster Reduction') + QGIS_APP = get_qgis_app() diff --git a/test/test_resources.py b/test/test_resources.py index 8511759..a432f9e 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -8,14 +8,13 @@ """ -__author__ = 'mario@anche.no' -__date__ = '2017-01-04' -__copyright__ = 'Copyright 2017, Mario Frasca' - import unittest from PyQt4.QtGui import QIcon +__author__ = 'mario@anche.no' +__date__ = '2017-01-04' +__copyright__ = 'Copyright 2017, Mario Frasca' class DistanceMatrixToCoordsDialogTest(unittest.TestCase): @@ -39,6 +38,3 @@ def test_icon_png(self): suite = unittest.makeSuite(DistanceMatrixToCoordsResourcesTest) runner = unittest.TextTestRunner(verbosity=2) runner.run(suite) - - - diff --git a/test/test_translations.py b/test/test_translations.py index 862b342..41a883a 100644 --- a/test/test_translations.py +++ b/test/test_translations.py @@ -8,15 +8,14 @@ """ from utilities import get_qgis_app +import unittest +import os +from PyQt4.QtCore import QCoreApplication, QTranslator __author__ = 'ismailsunni@yahoo.co.id' __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() diff --git a/test/test_utils.py b/test/test_utils.py index 63e1a69..3e50c15 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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) @@ -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)) diff --git a/test/utilities.py b/test/utilities.py index 0f4d965..33ac77c 100644 --- a/test/utilities.py +++ b/test/utilities.py @@ -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() @@ -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