From fb4924378e5ce36cda94f132ed49c9e3f28cd8b7 Mon Sep 17 00:00:00 2001 From: Zac Deziel Date: Fri, 17 Jan 2025 09:51:49 -0800 Subject: [PATCH] Test/base example (#190) * 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 --- .github/workflows/ci.yml | 17 ++++++- .gitignore | 1 + .python.env | 1 + .vscode/settings.json | 10 ++++ Map.py => ee_plugin/Map.py | 4 +- __init__.py => ee_plugin/__init__.py | 0 {contrib => ee_plugin/contrib}/__init__.py | 0 {contrib => ee_plugin/contrib}/palettes.py | 0 {contrib => ee_plugin/contrib}/utils.py | 0 ee_auth.py => ee_plugin/ee_auth.py | 0 ee_plugin.py => ee_plugin/ee_plugin.py | 4 +- {i18n => ee_plugin/i18n}/af.qm | Bin {i18n => ee_plugin/i18n}/af.ts | 0 {icons => ee_plugin/icons}/__init__.py | 0 {icons => ee_plugin/icons}/earth-engine.svg | 0 .../icons}/google-cloud-project.svg | 0 {icons => ee_plugin/icons}/google-cloud.svg | 0 {icons => ee_plugin/icons}/resources.py | 0 {icons => ee_plugin/icons}/resources.qrc | 0 metadata.txt => ee_plugin/metadata.txt | 0 provider.py => ee_plugin/provider.py | 1 + utils.py => ee_plugin/utils.py | 23 ++------- pavement.py | 8 ++-- pytest.ini | 3 -- requirements-dev.txt | 8 +++- .coverage => symbology-style.db | Bin 53248 -> 86016 bytes test/conftest.py | 30 ++++++++++++ test/test_init.py | 7 ++- test/test_map.py | 31 ++++++++++++ test/test_qgis_environment.py | 1 + test/test_resources.py | 6 +-- test/test_translations.py | 2 +- test/test_vector.py | 44 ++++++++++++++++++ 33 files changed, 161 insertions(+), 40 deletions(-) create mode 100644 .python.env create mode 100644 .vscode/settings.json rename Map.py => ee_plugin/Map.py (97%) rename __init__.py => ee_plugin/__init__.py (100%) rename {contrib => ee_plugin/contrib}/__init__.py (100%) rename {contrib => ee_plugin/contrib}/palettes.py (100%) rename {contrib => ee_plugin/contrib}/utils.py (100%) rename ee_auth.py => ee_plugin/ee_auth.py (100%) rename ee_plugin.py => ee_plugin/ee_plugin.py (99%) rename {i18n => ee_plugin/i18n}/af.qm (100%) rename {i18n => ee_plugin/i18n}/af.ts (100%) rename {icons => ee_plugin/icons}/__init__.py (100%) rename {icons => ee_plugin/icons}/earth-engine.svg (100%) rename {icons => ee_plugin/icons}/google-cloud-project.svg (100%) rename {icons => ee_plugin/icons}/google-cloud.svg (100%) rename {icons => ee_plugin/icons}/resources.py (100%) rename {icons => ee_plugin/icons}/resources.qrc (100%) rename metadata.txt => ee_plugin/metadata.txt (100%) rename provider.py => ee_plugin/provider.py (99%) rename utils.py => ee_plugin/utils.py (89%) delete mode 100644 pytest.ini rename .coverage => symbology-style.db (53%) create mode 100644 test/conftest.py create mode 100644 test/test_map.py create mode 100644 test/test_vector.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6afd704..892d854 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,14 +15,27 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up QGIS environment + - name: Set up QGIS environment run: | sudo apt update sudo apt install -y qgis python3-qgis python3-pyqt5 python3-pytest + + - name: Set Environment Variables + run: | + echo "QGIS_HOME=/usr" >> $GITHUB_ENV + echo "QT_QPA_PLATFORM=offscreen" >> $GITHUB_ENV + echo "DISPLAY=:99" >> $GITHUB_ENV + + - name: Start Virtual Display + run: Xvfb :99 -screen 0 1024x768x24 & + + - name: Configure Earth Engine Credentials + run: | + mkdir -p ~/.config/earthengine + echo '${{ secrets.EE_CREDENTIALS_JSON }}' > ~/.config/earthengine/credentials - name: Install dependencies run: | - python3 -m pip install --upgrade pip pip install -r requirements-dev.txt - name: Run pre-commit checks diff --git a/.gitignore b/.gitignore index ac96ab1..b389d6e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ temp venv .DS_Store htmlcov +.coverage \ No newline at end of file diff --git a/.python.env b/.python.env new file mode 100644 index 0000000..def5263 --- /dev/null +++ b/.python.env @@ -0,0 +1 @@ +PYTHONPATH=${PYTHONPATH}:./extlibs:/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.9 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..971f24a --- /dev/null +++ b/.vscode/settings.json @@ -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" + ], +} \ No newline at end of file diff --git a/Map.py b/ee_plugin/Map.py similarity index 97% rename from Map.py rename to ee_plugin/Map.py index c627e06..1374ac8 100644 --- a/Map.py +++ b/ee_plugin/Map.py @@ -27,9 +27,9 @@ def addLayer(eeObject, visParams=None, name=None, shown=True, opacity=1.0): >>> from ee_plugin import Map >>> Map.addLayer(.....) """ - from .utils import add_or_update_ee_layer + from . import utils - add_or_update_ee_layer(eeObject, visParams, name, shown, opacity) + utils.add_or_update_ee_layer(eeObject, visParams, name, shown, opacity) def centerObject(feature, zoom=None): diff --git a/__init__.py b/ee_plugin/__init__.py similarity index 100% rename from __init__.py rename to ee_plugin/__init__.py diff --git a/contrib/__init__.py b/ee_plugin/contrib/__init__.py similarity index 100% rename from contrib/__init__.py rename to ee_plugin/contrib/__init__.py diff --git a/contrib/palettes.py b/ee_plugin/contrib/palettes.py similarity index 100% rename from contrib/palettes.py rename to ee_plugin/contrib/palettes.py diff --git a/contrib/utils.py b/ee_plugin/contrib/utils.py similarity index 100% rename from contrib/utils.py rename to ee_plugin/contrib/utils.py diff --git a/ee_auth.py b/ee_plugin/ee_auth.py similarity index 100% rename from ee_auth.py rename to ee_plugin/ee_auth.py diff --git a/ee_plugin.py b/ee_plugin/ee_plugin.py similarity index 99% rename from ee_plugin.py rename to ee_plugin/ee_plugin.py index 1413f4e..0248364 100644 --- a/ee_plugin.py +++ b/ee_plugin/ee_plugin.py @@ -17,8 +17,6 @@ from qgis.PyQt.QtGui import QIcon from qgis.PyQt.QtWidgets import QAction -from ee_plugin import provider - # read the plugin version from metadata cfg = configparser.ConfigParser() cfg.read(os.path.join(os.path.dirname(__file__), "metadata.txt")) @@ -37,6 +35,8 @@ def __init__(self, iface): application at run time. :type iface: QgsInterface """ + from . import provider + # Save reference to the QGIS interface self.iface = iface diff --git a/i18n/af.qm b/ee_plugin/i18n/af.qm similarity index 100% rename from i18n/af.qm rename to ee_plugin/i18n/af.qm diff --git a/i18n/af.ts b/ee_plugin/i18n/af.ts similarity index 100% rename from i18n/af.ts rename to ee_plugin/i18n/af.ts diff --git a/icons/__init__.py b/ee_plugin/icons/__init__.py similarity index 100% rename from icons/__init__.py rename to ee_plugin/icons/__init__.py diff --git a/icons/earth-engine.svg b/ee_plugin/icons/earth-engine.svg similarity index 100% rename from icons/earth-engine.svg rename to ee_plugin/icons/earth-engine.svg diff --git a/icons/google-cloud-project.svg b/ee_plugin/icons/google-cloud-project.svg similarity index 100% rename from icons/google-cloud-project.svg rename to ee_plugin/icons/google-cloud-project.svg diff --git a/icons/google-cloud.svg b/ee_plugin/icons/google-cloud.svg similarity index 100% rename from icons/google-cloud.svg rename to ee_plugin/icons/google-cloud.svg diff --git a/icons/resources.py b/ee_plugin/icons/resources.py similarity index 100% rename from icons/resources.py rename to ee_plugin/icons/resources.py diff --git a/icons/resources.qrc b/ee_plugin/icons/resources.qrc similarity index 100% rename from icons/resources.qrc rename to ee_plugin/icons/resources.qrc diff --git a/metadata.txt b/ee_plugin/metadata.txt similarity index 100% rename from metadata.txt rename to ee_plugin/metadata.txt diff --git a/provider.py b/ee_plugin/provider.py similarity index 99% rename from provider.py rename to ee_plugin/provider.py index 9d92705..7a6c7c3 100644 --- a/provider.py +++ b/ee_plugin/provider.py @@ -58,6 +58,7 @@ def __init__(self, *args, **kwargs): # create WMS provider self.wms = QgsProviderRegistry.instance().createProvider("wms", *args, **kwargs) + assert self.wms, f"Failed to create WMS provider: {args}, {kwargs}" @classmethod def description(cls): diff --git a/utils.py b/ee_plugin/utils.py similarity index 89% rename from utils.py rename to ee_plugin/utils.py index f2298a7..4d4e33e 100644 --- a/utils.py +++ b/ee_plugin/utils.py @@ -16,7 +16,7 @@ QgsRectangle, ) -import ee_plugin +from .ee_plugin import VERSION as ee_plugin_version def get_ee_image_url(image): @@ -27,7 +27,6 @@ def get_ee_image_url(image): def update_ee_layer_properties(layer, eeObject, visParams, shown, opacity): layer.dataProvider().set_ee_object(eeObject) - layer.setCustomProperty("ee-layer", True) if opacity is not None: @@ -38,7 +37,7 @@ def update_ee_layer_properties(layer, eeObject, visParams, shown, opacity): # serialize EE code ee_object = eeObject.serialize() ee_object_vis = json.dumps(visParams) - layer.setCustomProperty("ee-plugin-version", ee_plugin.ee_plugin.VERSION) + layer.setCustomProperty("ee-plugin-version", ee_plugin_version) layer.setCustomProperty("ee-object", ee_object) layer.setCustomProperty("ee-object-vis", ee_object_vis) @@ -51,23 +50,7 @@ def add_ee_image_layer(image, name, shown, opacity): check_version() url = "type=xyz&url=" + get_ee_image_url(image) - - # EE raster data provider - if image.ee_type == ee.Image: - layer = QgsRasterLayer(url, name, "EE") - # EE vector data provider - if image.ee_type in [ee.Geometry, ee.Feature]: - # TODO - layer = QgsRasterLayer(url, name, "wms") - # EE raster collection data provider - if image.ee_type == ee.ImageCollection: - # TODO - layer = QgsRasterLayer(url, name, "wms") - # EE vector collection data provider - if image.ee_type == ee.FeatureCollection: - # TODO - layer = QgsRasterLayer(url, name, "wms") - + layer = QgsRasterLayer(url, name, "EE") QgsProject.instance().addMapLayer(layer) if shown is not None: diff --git a/pavement.py b/pavement.py index 4cc13c3..67e47ed 100644 --- a/pavement.py +++ b/pavement.py @@ -11,8 +11,8 @@ options( plugin=Bunch( name="ee_plugin", - ext_libs=path("extlibs"), - source_dir=path("."), + ext_libs=path(os.path.join("ee_plugin", "extlibs")), + source_dir=path("ee_plugin"), package_dir=path("."), tests=["test", "tests"], excludes=[ @@ -76,7 +76,7 @@ def setup(): def install(options): """install plugin to qgis""" plugin_name = options.plugin.name - src = path(__file__).dirname() + src = options.plugin.source_dir if platform.system() == "Windows": dst = ( path( @@ -149,5 +149,5 @@ def filter_excludes(files): for root, dirs, files in os.walk(src_dir): for f in filter_excludes(files): relpath = os.path.relpath(root, ".") - zipFile.write(path(root) / f, path("ee_plugin") / path(relpath) / f) + zipFile.write(path(root) / f, path(relpath) / f) filter_excludes(dirs) diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index bfc3e7d..0000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -addopts = --cov=. --cov-report=term-missing -norecursedirs = extlibs \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 9011ff4..a4cb024 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,10 @@ -r requirements.txt # Include all main requirements # Development dependencies -pytest +pytest==7.4.3 # pytest-qgis does not support pytest>=8 pytest-cov -pre-commit \ No newline at end of file +pytest-qgis==2.1.0 +pre-commit +pyqt5 +future +paver \ No newline at end of file diff --git a/.coverage b/symbology-style.db similarity index 53% rename from .coverage rename to symbology-style.db index c4810d5b8882ebb77d4831e7d4d8329f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XCbRy`nq=l>`2 zPfNw;#ZL>57oIJ=zvveJk$)xsbn)-{K5<2Sw3IEqS^9?l6TMYBSDd{At{x&l00ck) z1V8`;KmY_lK$4EDy|JN3hMUL#6A!69F`}G-pT*dT5OX$N%CJ%GIF-B;)_mQMD%zox4B&*AFSHLuZf1|HTK?o-%aaf$@J~ zGy(nbfBw@dtp_*yh<3yHUwcID?Ys?fgX90)=(0AA|Fa{tz)j=-%vrTpxsBr8V*H;T zU9-XQzdDj{*f{=IMwc?+7*f=r6m3|W8W4c>|Iqn@00@8p2!H?xfB*=900@8p2!Oyn zO+b+qN$2^0S^QU`4>k}00T2KI5C8!X009sH0T2KI5CDODkbt7-8qfc0;%k!lkGLsb z7rzs~5HE@!if8B)HV^;-5C8!X009sH0T2KI5C8!X0D=E60bNsN?Sq>7o#&r>^xubN zEk}nFxxo69s%1G!>opvi$Y&_}zRYV!K9))GKBZ=5RnxXVr+$&=|26S5NxV(#|Gz2zB5sJ^i&w<2=oB^(009sH z0T2KI5C8!X009sH0T2LzyN3Y(3m|J+xXb0jT{au;GMR9fPKP^H4R?wX?ouh0{sIW+ z|D|nrPhp@52!H?xfB*=900@8p2!H?xfB*=9z?~<+^ZywC-+8W(2m&Ag0w4eaAOHd& z00JNY0w4eacM}1A|9?V!lb`>8OZ-#3L2Cf~S^SaS0r;)>jrgVbxp+yuAbu= diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..fccc0a5 --- /dev/null +++ b/test/conftest.py @@ -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 diff --git a/test/test_init.py b/test/test_init.py index 71c65c0..a1f4ee6 100644 --- a/test/test_init.py +++ b/test/test_init.py @@ -47,7 +47,12 @@ def test_read_init(self): ] file_path = os.path.abspath( - os.path.join(os.path.dirname(__file__), os.pardir, "metadata.txt") + os.path.join( + os.path.dirname(__file__), + os.pardir, + "ee_plugin", + "metadata.txt", + ) ) LOGGER.info(file_path) metadata = [] diff --git a/test/test_map.py b/test/test_map.py new file mode 100644 index 0000000..913f06f --- /dev/null +++ b/test/test_map.py @@ -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." diff --git a/test/test_qgis_environment.py b/test/test_qgis_environment.py index 3be9b64..3d6535d 100644 --- a/test/test_qgis_environment.py +++ b/test/test_qgis_environment.py @@ -34,6 +34,7 @@ def test_qgis_environment(self): r = QgsProviderRegistry.instance() self.assertIn("gdal", r.providerList()) self.assertIn("ogr", r.providerList()) + self.assertIn("wms", r.providerList()) # needed for our EE provider def test_projection(self): """Test that QGIS properly parses a wkt string.""" diff --git a/test/test_resources.py b/test/test_resources.py index d9688e9..1be071d 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -14,9 +14,9 @@ class GoogleEarthEngineResourcesTest(unittest.TestCase): def test_icon_png(self): """Test image paths exist""" paths = ( - "icons/google-cloud-project.svg", - "icons/google-cloud.svg", - "./icons/earth-engine.svg", + "ee_plugin/icons/google-cloud-project.svg", + "ee_plugin/icons/google-cloud.svg", + "ee_plugin/icons/earth-engine.svg", ) for path in paths: icon = QIcon(path) diff --git a/test/test_translations.py b/test/test_translations.py index 31a1358..f2d1ddc 100644 --- a/test/test_translations.py +++ b/test/test_translations.py @@ -43,7 +43,7 @@ def test_qgis_translations(self): """Test that translations work.""" parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir) dir_path = os.path.abspath(parent_path) - file_path = os.path.join(dir_path, "i18n", "af.qm") + file_path = os.path.join(dir_path, "ee_plugin", "i18n", "af.qm") translator = QTranslator() translator.load(file_path) QCoreApplication.installTranslator(translator) diff --git a/test/test_vector.py b/test/test_vector.py new file mode 100644 index 0000000..c43ac43 --- /dev/null +++ b/test/test_vector.py @@ -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"