Skip to content

Commit

Permalink
Authenticate with Earth Engine in Xee integration tests.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 580705612
  • Loading branch information
Xee authors committed Nov 9, 2023
1 parent c97c6f2 commit 07b8676
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
permissions:
id-token: write # This is required for requesting the JWT.
steps:
- name: Cancel previous
uses: styfle/[email protected]
Expand All @@ -55,10 +57,13 @@ jobs:
- name: Install Xee
run: |
pip install -e .[tests]
- uses: 'actions/checkout@v4'
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
service_account: ${{ secrets.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
- name: Run unit tests
run: |
pytest xee
- name: Run scripts tests
# The scripts may define some of the same flags, so we run pytest in separate processes.
run: |
for test in examples/*_test.py; do pytest $test; done
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
description="A Google Earth Engine extension for Xarray.",
long_description=open("README.md", "r", encoding="utf-8").read(),
long_description_content_type="text/markdown",
install_requires=["xarray", "earthengine-api>=0.1.374", "pyproj", "affine"],
install_requires=[
"xarray[parallel]",
"earthengine-api>=0.1.374",
"pyproj",
"affine",
],
extras_require={
"tests": tests_requires,
"examples": examples_require,
Expand Down
24 changes: 22 additions & 2 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,39 @@
# limitations under the License.
# ==============================================================================
r"""Integration tests for the Google Earth Engine backend for Xarray."""
import json
import os
import pathlib

from absl.testing import absltest
from google.auth import identity_pool
import numpy as np
import xarray as xr
from xarray.core import indexing
import xee

import ee

_CREDENTIALS_PATH_KEY = 'GOOGLE_APPLICATION_CREDENTIALS'
_SCOPES = [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/earthengine',
]


def _read_identity_pool_creds() -> identity_pool.Credentials:
credentials_path = os.environ[_CREDENTIALS_PATH_KEY]
with open(credentials_path) as file:
json_file = json.load(file)
credentials = identity_pool.Credentials.from_info(json_file)
return credentials.with_scopes(_SCOPES)


def init_ee_for_tests():
ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com')
ee.Initialize(
credentials=_read_identity_pool_creds(),
opt_url=ee.data.HIGH_VOLUME_API_BASE_URL,
)


class EEBackendArrayTest(absltest.TestCase):
Expand Down Expand Up @@ -337,7 +357,7 @@ def test_parses_ee_url(self):
scale=25.0, # in degrees
n_images=3,
)
self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 7})
self.assertEqual(dict(ds.dims), {'time': 3, 'lon': 15, 'lat': 8})
ds = self.entry.open_dataset(
'ee:LANDSAT/LC08/C01/T1',
drop_variables=tuple(f'B{i}' for i in range(3, 12)),
Expand Down

0 comments on commit 07b8676

Please sign in to comment.