From 5a51e8bd312365d550e644eb47e35f9730a64fca Mon Sep 17 00:00:00 2001
From: "benjamin.jakimow@geo.hu-berlin.de" <q8DTkxUg-BB>
Date: Tue, 6 Mar 2018 19:16:10 +0100
Subject: [PATCH] added & refactored /tests

---
 test/qgis_interface.py         | 12 +++---
 test/test_init.py              | 41 ++++++++++---------
 test/test_plotstyling.py       | 62 +++++++++++++++++++++++------
 test/test_spectrallibraries.py | 72 ++++++++++++++++++++++++++++++++++
 4 files changed, 149 insertions(+), 38 deletions(-)
 create mode 100644 test/test_spectrallibraries.py

diff --git a/test/qgis_interface.py b/test/qgis_interface.py
index 3a65ed5e..ca7e6614 100644
--- a/test/qgis_interface.py
+++ b/test/qgis_interface.py
@@ -25,7 +25,7 @@ __copyright__ = (
 
 import logging
 from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal
-from qgis.core import QgsMapLayerRegistry
+from qgis.core import QgsProject
 from qgis.gui import QgsMapCanvasLayer
 LOGGER = logging.getLogger('QGIS')
 
@@ -49,11 +49,11 @@ class QgisInterface(QObject):
         # are added.
         LOGGER.debug('Initialising canvas...')
         # noinspection PyArgumentList
-        QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers)
+        QgsProject.instance().layersAdded.connect(self.addLayers)
         # noinspection PyArgumentList
-        QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer)
+        QgsProject.instance().layerWasAdded.connect(self.addLayer)
         # noinspection PyArgumentList
-        QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers)
+        QgsProject.instance().removeAll.connect(self.removeAllLayers)
 
         # For processing module
         self.destCrs = None
@@ -102,7 +102,7 @@ class QgisInterface(QObject):
     def newProject(self):
         """Create new project."""
         # noinspection PyArgumentList
-        QgsMapLayerRegistry.instance().removeAllMapLayers()
+        QgsProject.instance().removeAllMapLayers()
 
     # ---------------- API Mock for QgsInterface follows -------------------
 
@@ -150,7 +150,7 @@ class QgisInterface(QObject):
     def activeLayer(self):
         """Get pointer to the active layer (layer selected in the legend)."""
         # noinspection PyArgumentList
-        layers = QgsMapLayerRegistry.instance().mapLayers()
+        layers = QgsProject.instance().mapLayers()
         for item in layers:
             return layers[item]
 
diff --git a/test/test_init.py b/test/test_init.py
index 1880b3a3..053333c6 100644
--- a/test/test_init.py
+++ b/test/test_init.py
@@ -1,21 +1,24 @@
-# coding=utf-8
-"""Tests QGIS plugin init."""
-
-
-__author__ = 'Tim Sutton <tim@linfiniti.com>'
-__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')
-
+# -*- coding: utf-8 -*-
+
+"""
+***************************************************************************
+
+    ---------------------
+    Date                 : 30.11.2017
+    Copyright            : (C) 2017 by Benjamin Jakimow
+    Email                : benjamin jakimow at geo dot hu-berlin dot de
+***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************
+"""
+# noinspection PyPep8Naming
+
+import os, sys, unittest, configparser
 
 class TestInit(unittest.TestCase):
     """Test that the plugin init is usable for QGIS.
@@ -45,7 +48,7 @@ class TestInit(unittest.TestCase):
         file_path = os.path.abspath(os.path.join(
             os.path.dirname(__file__), os.pardir,
             'metadata.txt'))
-        LOGGER.info(file_path)
+
         metadata = []
         parser = configparser.ConfigParser()
         parser.optionxform = str
diff --git a/test/test_plotstyling.py b/test/test_plotstyling.py
index a9f3a2f5..29876118 100644
--- a/test/test_plotstyling.py
+++ b/test/test_plotstyling.py
@@ -1,21 +1,26 @@
-# coding=utf-8
-"""Safe Translations Test.
+# -*- coding: utf-8 -*-
 
-.. note:: This program is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published by
-     the Free Software Foundation; either version 2 of the License, or
-     (at your option) any later version.
+"""
+***************************************************************************
 
+    ---------------------
+    Date                 : 30.11.2017
+    Copyright            : (C) 2017 by Benjamin Jakimow
+    Email                : benjamin jakimow at geo dot hu-berlin dot de
+***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************
 """
+# noinspection PyPep8Naming
+
 
-from utilities import get_qgis_app
 
-__author__ = 'ismailsunni@yahoo.co.id'
-__date__ = '12/10/2011'
-__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
-                 'Disaster Reduction')
-import unittest
-import os
+import os, unittest
 from timeseriesviewer.utils import initQgisApplication
 QGIS_APP = initQgisApplication()
 
@@ -41,5 +46,36 @@ class TestPlotStyling(unittest.TestCase):
         s2 = pickle.loads(pickle.dumps(s1))
         self.assertEqual(s1,s2)
 
+
+    def test_dialogs(self):
+
+        s1 = PlotStyle()
+
+        s1.markerPen.setColor(QColor('yellow'))
+
+        s2 = PlotStyle(plotStyle=s1)
+
+        self.assertEqual(s1,s2)
+
+
+
+        d = PlotStyleDialog()
+        self.assertIsInstance(d, PlotStyleDialog)
+
+        try:
+            d.show()
+            d.setPlotStyle(s1)
+        except Exception:
+            self.fail('Unable to initialize PlotStyleDialog')
+
+        self.assertEqual(s1, d.plotStyle())
+
+        try:
+            btn = PlotStyleButton()
+            btn.show()
+        except Exception:
+            self.fail('Unable to initialize PlotStyleButton')
+
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/test/test_spectrallibraries.py b/test/test_spectrallibraries.py
new file mode 100644
index 00000000..5bfe2199
--- /dev/null
+++ b/test/test_spectrallibraries.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+
+"""
+***************************************************************************
+
+    ---------------------
+    Date                 : 30.11.2017
+    Copyright            : (C) 2017 by Benjamin Jakimow
+    Email                : benjamin jakimow at geo dot hu-berlin dot de
+***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************
+"""
+# noinspection PyPep8Naming
+import os, sys, unittest
+from timeseriesviewer.utils import initQgisApplication
+qapp = initQgisApplication()
+
+from timeseriesviewer.spectrallibraries import *
+
+class TestInit(unittest.TestCase):
+
+    def setUp(self):
+
+        self.SP = None
+        self.SPECLIB = None
+
+    def test_spectralprofile(self):
+        spec1 = SpectralProfile()
+        spec1.setValues([0,4,3,2,1],['-'], [450,500,750, 1000, 1500], 'nm')
+
+
+        values = [('key','value'),('key', 100),('Üä','ÜmlÄute')]
+        for md in values:
+            k, v = md
+            spec1.setMetadata(k,v)
+            v2 = spec1.metadata(k)
+            self.assertEqual(v,v2)
+
+        self.SP = spec1
+
+    def test_spectralLibrary(self):
+        sl = SpectralLibrary()
+        sl.addProfile(self.SP)
+
+        self.assertEqual(len(sl),1)
+        self.assertEqual(sl[0], self.SP)
+
+
+        self.SPECLIB = sl
+
+    def test_speclibWidget(self):
+        p = SpectralLibraryWidget()
+        p.addSpeclib(self.SPECLIB)
+        p.show()
+
+
+
+
+
+
+
+        pass
+
+
+if __name__ == '__main__':
+    unittest.main()
-- 
GitLab