-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Writing some initial tests for Map.py using pytest-qgis * Add proper registration of WMS provider * wip to test add_layers functionality * Add python env file to use extlibs as pythonpath * Debug adding provider * Base example test implemented * Update CI to authenticate to earthengine * Add test to pythonpath * Revert pytest call in CI * Add pythonpath * Simplify test execution in CI * Add future for CI dependencies * Reorganized plugin code into a module * Activate virtualenv to avoid system wide permissions error * Update python version to 3.9 * Move plugin files to ee_plugin module Clean up installed plugin to include only extlibs and python files. * Modify path for paver package to avoid nested ee_plugin * Add icons, i18n, and contrib to paver packaging * Update path to ee_plugin module * Add paver to dev requirements * Bug 195/add vector layer (#196) * Move fixtures to separate conftest.py file The goal will be to reuse the fixture for other tests * Add unit test reproducing the bud * Fix bug adding vector layers by creating layers with the EE flag * Simplify code paths layer is a QgsRasterLayer in any case --------- Co-authored-by: Anthony Lukach <[email protected]>
- Loading branch information
Showing
33 changed files
with
161 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ temp | |
venv | ||
.DS_Store | ||
htmlcov | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PYTHONPATH=${PYTHONPATH}:./extlibs:/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"python.envFile": "${workspaceFolder}/.python.env", | ||
"terminal.integrated.env.osx": { | ||
"PYTHONPATH": "${PYTHONPATH}:./extlibs:/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.9" | ||
}, | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.pytestArgs": [ | ||
"test" | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ee | ||
from pytest import fixture | ||
from qgis.utils import plugins | ||
from PyQt5.QtCore import QSettings, QCoreApplication | ||
|
||
from ee_plugin.ee_plugin import GoogleEarthEnginePlugin | ||
|
||
|
||
@fixture(scope="session", autouse=True) | ||
def setup_ee(): | ||
"""Initialize the Earth Engine API.""" | ||
print("Initializing Earth Engine API...") | ||
ee.Initialize() | ||
ee.Authenticate(auth_mode="localhost", quiet=True) | ||
|
||
|
||
@fixture(scope="session", autouse=True) | ||
def load_ee_plugin(qgis_app, setup_ee): | ||
"""Load Earth Engine plugin and configure QSettings.""" | ||
|
||
# Set QSettings values required by the plugin | ||
QCoreApplication.setOrganizationName("QGIS") | ||
QCoreApplication.setApplicationName("QGIS Testing") | ||
QSettings().setValue("locale/userLocale", "en") | ||
|
||
# Initialize and register the plugin | ||
plugin = GoogleEarthEnginePlugin(qgis_app) | ||
plugins["ee_plugin"] = plugin | ||
plugin.check_version() | ||
yield qgis_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from ee_plugin import Map | ||
|
||
|
||
def test_add_layer(): | ||
"""Test adding a layer to the map.""" | ||
import ee | ||
|
||
image = ee.Image("USGS/SRTMGL1_003") | ||
vis_params = { | ||
"min": 0, | ||
"max": 4000, | ||
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"], | ||
} | ||
|
||
# Add the layer to the map | ||
Map.addLayer(image, vis_params, "DEM") | ||
|
||
|
||
def test_get_bounds(): | ||
"""Test getting the bounds of the map.""" | ||
bounds = Map.getBounds() | ||
assert len(bounds) == 4, "Bounds do not have the expected format." | ||
assert all( | ||
isinstance(coord, (float, int)) for coord in bounds | ||
), "Bounds coordinates are not numeric." | ||
|
||
|
||
def test_get_scale(): | ||
"""Test getting the map scale.""" | ||
scale = Map.getScale() | ||
assert scale > 0, "Scale should be a positive number." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ee | ||
import pytest | ||
|
||
from ee_plugin import Map | ||
|
||
# initialize the Earth Engine API is required to use the ee.Geometry module | ||
# and runs before fixtures | ||
ee.Initialize() | ||
|
||
geometries = [ | ||
(ee.Geometry.Point([1.5, 1.5]), {"color": "1eff05"}, "point"), | ||
( | ||
ee.Geometry.LineString([[-35, -10], [35, -10], [35, 10], [-35, 10]]), | ||
{"color": "FF0000"}, | ||
"lineString", | ||
), | ||
( | ||
ee.Geometry.LinearRing( | ||
[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]] | ||
), | ||
{"color": "ee38ff"}, | ||
"linearRing", | ||
), | ||
(ee.Geometry.Rectangle([-40, -20, 40, 20]), {"color": "ffa05c"}, "rectangle"), | ||
( | ||
ee.Geometry.Polygon([[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 40]]]), | ||
{"color": "FF0000"}, | ||
"geodesic polygon", | ||
), | ||
( | ||
ee.Geometry( | ||
ee.Geometry.Polygon([[[-5, 40], [65, 40], [65, 60], [-5, 60], [-5, 40]]]), | ||
None, | ||
False, | ||
), | ||
{"color": "000000"}, | ||
"planar polygon", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("geometry, vis_params, layer_name", geometries) | ||
def test_add_geometry_layer(geometry, vis_params, layer_name): | ||
Map.addLayer(geometry, vis_params, layer_name), "Layer added successfully" |