Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- 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, configparser
from eotimeseriesviewer.tests import initQgisApplication, testRasterFiles
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtCore import *
from qgis.core import *
from qgis.gui import *
from qgis.testing import TestCase
import unittest, tempfile
import eotimeseriesviewer
eotimeseriesviewer.initResources()
from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.tests import TestObjects
QGIS_APP = initQgisApplication()
SHOW_GUI = True and os.environ.get('CI') is None
class TestInit(TestCase):
"""Test that the plugin init is usable for QGIS.
Based heavily on the validator class by Alessandro
Passoti available here:
http://github.com/qgis/qgis-django/blob/master/qgis-app/
plugins/validator.py
"""
def test_syncExtents(self):
from eotimeseriesviewer.main import TimeSeriesViewer
TSV = TimeSeriesViewer()
TSV.show()
TSV.loadExampleTimeSeries()
from example import exampleEvents
lyr = QgsVectorLayer(exampleEvents)
QgsProject.instance().addMapLayer(lyr)
from qgis.utils import iface
self.assertIsInstance(iface, QgisInterface)
qgisCanvas = iface.mapCanvas()
world = SpatialExtent.world()
qgisCanvas.setDestinationCrs(world.crs())
qgisCanvas.setExtent(world)
qcenter1 = qgisCanvas.center()
self.assertTrue(qgisCanvas.mapSettings().destinationCrs().isValid())
self.assertIsInstance(qgisCanvas, QgsMapCanvas)
TSV.ui.optionSyncMapCenter.setChecked(True)
extent = TSV.spatialTemporalVis.spatialExtent()
self.assertIsInstance(extent, SpatialExtent)
center = extent.spatialCenter()
self.assertIsInstance(center, SpatialPoint)
center2 = SpatialPoint(center.crs(), center.x() + 100, center.y() + 100)
TSV.spatialTemporalVis.mSyncLock = False
TSV.setSpatialCenter(center2)
self.assertEqual(TSV.spatialCenter(), center2)
qcenter2 = qgisCanvas.center()
self.assertNotEqual(qcenter1, qcenter2)
TSV.ui.optionSyncMapCenter.setChecked(False)
TSV.spatialTemporalVis.mSyncLock = False
TSV.setSpatialCenter(center)
self.assertNotEqual(qcenter2, qgisCanvas.center())
if SHOW_GUI:
QGIS_APP.exec_()
if __name__ == '__main__':
unittest.main()