Commit bbf7db00 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

WIP refactorign tests

parent 5fde708b
......@@ -26,12 +26,14 @@ from eotimeseriesviewer.tests import start_app, testRasterFiles
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.core import *
from qgis.core import QgsProject, QgsApplication
from qgis.gui import *
from qgis.testing import TestCase
import unittest
import tempfile
from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.tests import TestObjects, EOTSVTestCase
from eotimeseriesviewer.main import *
......@@ -93,7 +95,7 @@ class TestMain(EOTSVTestCase):
TSV.setCurrentDate(tsd)
# save and read settings
path = self.testOutputDirectory() / 'test.qgz'
path = self.createTestOutputDirectory() / 'test.qgz'
QgsProject.instance().write(path.as_posix())
self.assertTrue(QgsProject.instance().read(path.as_posix()))
TSV.onReloadProject()
......@@ -139,7 +141,6 @@ class TestMain(EOTSVTestCase):
self.assertIsInstance(dialog, QDialog)
self.showGui([dialog])
def test_exportMapsToImages(self):
from eotimeseriesviewer.main import EOTimeSeriesViewer, SaveAllMapsDialog
......
......@@ -17,23 +17,26 @@
***************************************************************************
"""
# noinspection PyPep8Naming
import unittest
import os
import xmlrunner
from eotimeseriesviewer.tests import start_app, testRasterFiles, TestObjects, EOTSVTestCase
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
import unittest
import tempfile
import xmlrunner
from qgis.PyQt.QtWidgets import *
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsWkbTypes, QgsProject
from qgis.gui import QgsMapCanvas, QgsFontButton
from eotimeseriesviewer import SpatialPoint
from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.timeseries import *
from eotimeseriesviewer.mapcanvas import MapCanvas, MapCanvasInfoItem
from eotimeseriesviewer.timeseries import TimeSeries
# set to False to show GUI elements
# set to False to show GUI elements
class TestMapCanvas(EOTSVTestCase):
"""Test resources work."""
def test_basic_behaviour(self):
files = TestObjects.testImagePaths()
......@@ -41,7 +44,6 @@ class TestMapCanvas(EOTSVTestCase):
self.assertTrue(lyr1.isValid())
QgsProject.instance().addMapLayer(lyr1)
c = QgsMapCanvas()
c.setWindowTitle('QgsMapCanvas test')
self.assertIsInstance(c, QgsMapCanvas)
......@@ -57,7 +59,6 @@ class TestMapCanvas(EOTSVTestCase):
self.assertTrue(bExtent == 1)
c.setLayers([lyr1])
c.setDestinationCrs(lyr1.crs())
c.setExtent(lyr1.extent())
......@@ -74,8 +75,7 @@ class TestMapCanvas(EOTSVTestCase):
canvas.setDestinationCrs(lyr1.crs())
canvas.setExtent(lyr1.extent())
pos = QPoint(int(canvas.width()*0.5), int(canvas.height()*0.5))
pos = QPoint(int(canvas.width() * 0.5), int(canvas.height() * 0.5))
menu = canvas.contextMenu(pos)
self.assertIsInstance(menu, QMenu)
......@@ -100,7 +100,6 @@ class TestMapCanvas(EOTSVTestCase):
mc.mInfoItem.setMiddleLeft('Middle\nLeft')
mc.mInfoItem.setLowerLeft('Lower\nLeft')
mc.mInfoItem.setUpperCenter('Upper\nCenter')
mc.mInfoItem.setMiddleCenter('Middle\nCenter')
mc.mInfoItem.setLowerCenter('Lower\nCenter')
......@@ -112,8 +111,7 @@ class TestMapCanvas(EOTSVTestCase):
if False:
for k in mc.mInfoItem.mText.keys():
v = mc.mInfoItem.mText[k]
mc.mInfoItem.mText[k] = v.replace('\n' ,' ')
mc.mInfoItem.mText[k] = v.replace('\n', ' ')
item = mc.mInfoItem
self.assertIsInstance(item, MapCanvasInfoItem)
......@@ -121,14 +119,14 @@ class TestMapCanvas(EOTSVTestCase):
btn.setMapCanvas(mc)
btn.setTextFormat(item.textFormat())
def onChanged():
mc.mInfoItem.setTextFormat(btn.textFormat())
mc.update()
btn.changed.connect(onChanged)
if False:
w= QWidget()
w = QWidget()
w.setLayout(QVBoxLayout())
w.layout().addWidget(btn)
w.layout().addWidget(mc)
......@@ -141,7 +139,6 @@ class TestMapCanvas(EOTSVTestCase):
lyr1 = QgsRasterLayer(files[0])
lyr2 = QgsRasterLayer(files[1])
canvas = MapCanvas()
canvas.setWindowTitle('timeseriesviewer.MapCanvas')
canvas.setDestinationCrs(lyr1.crs())
......@@ -159,15 +156,16 @@ class TestMapCanvas(EOTSVTestCase):
self.showGui([canvas])
def test_mapTools(self):
m = MapCanvas()
lastPos = None
def onChanged(position:SpatialPoint):
def onChanged(position: SpatialPoint):
nonlocal lastPos
lastPos = position
m.sigCrosshairPositionChanged.connect(onChanged)
center = SpatialPoint.fromMapCanvasCenter(m)
......@@ -178,7 +176,7 @@ class TestMapCanvas(EOTSVTestCase):
self.assertTrue(m.crosshairPosition() == center)
p2 = SpatialPoint(center.crs(), center)
p2.setX(p2.x()+100)
p2.setX(p2.x() + 100)
m.setCrosshairPosition(p2)
self.assertIsInstance(lastPos, SpatialPoint)
self.assertTrue(lastPos == p2)
......
......@@ -18,25 +18,16 @@
"""
# noinspection PyPep8Naming
import os
import sys
import unittest
import configparser
import unittest
import os
import xmlrunner
from eotimeseriesviewer.tests import start_app, testRasterFiles
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.core import *
from qgis.gui import *
import unittest, tempfile
import eotimeseriesviewer
from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.tests import TestObjects, EOTSVTestCase
from qgis.core import QgsMapLayer, QgsRasterLayer, QgsVectorLayer, QgsProject
from qgis.gui import QgsMapToolZoom, QgsMapToolPan
from eotimeseriesviewer.mapcanvas import MapCanvas
from eotimeseriesviewer.tests import EOTSVTestCase
from eotimeseriesviewer.externals.qps.maptools import MapTools, MapToolCenter, \
FullExtentMapTool, PixelScaleExtentMapTool, QgsMapToolAddFeature, CursorLocationMapTool, QgsMapToolSelect
class TestMapTools(EOTSVTestCase):
"""Test that the plugin init is usable for QGIS.
......@@ -111,8 +102,6 @@ class TestMapTools(EOTSVTestCase):
TSV.setMapTool(MapTools.CursorLocation)
self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), CursorLocationMapTool)
from eotimeseriesviewer import SpectralProfileMapTool, TemporalProfileMapTool
#TSV.setMapTool(MapTools.SpectralProfile)
#self.assertIsInstance(TSV.mapCanvases()[0].mapTool(), SpectralProfileMapTool)
......
......@@ -74,12 +74,12 @@ class TestTimeSeries(EOTSVTestCase):
self.assertTrue(len(ts) == len(files))
# save time series, absolute paths
pathTSFileAbs = self.testOutputDirectory() / 'timeseries_abs.txt'
pathTSFileAbs = self.createTestOutputDirectory()() / 'timeseries_abs.txt'
ts.saveToFile(pathTSFileAbs, relative_path=False)
self.assertTrue(os.path.isfile(pathTSFileAbs))
# save time series, relative paths
pathTSFileRel = self.testOutputDirectory() / 'timeseries_rel.txt'
pathTSFileRel = self.createTestOutputDirectory()() / 'timeseries_rel.txt'
ts.saveToFile(pathTSFileRel, relative_path=False)
self.assertTrue(os.path.isfile(pathTSFileRel))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment