Skip to content

Commit

Permalink
Get integration tests running.
Browse files Browse the repository at this point in the history
  • Loading branch information
naschmitz committed Nov 5, 2023
1 parent efc0b98 commit c349685
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
permissions:
id-token: write # This is required for requesting the JWT
steps:
- name: Cancel previous
uses: styfle/[email protected]
with:
Expand All @@ -55,10 +57,17 @@ jobs:
- name: Install Xee
run: |
pip install -e .[tests]
- name: Run unit tests
# Fix an issue with "Unrecognized chunk manager. Must be one of []."
- name: Fix xarray installation
run: |
pytest xee
- name: Run scripts tests
# The scripts may define some of the same flags, so we run pytest in separate processes.
pip install --force-reinstall "xarray==0.21.1"
- 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: |
for test in examples/*_test.py; do pytest $test; done
pytest xee
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

tests_requires = [
"absl-py",
"dask",
"pytest",
"pyink",
]
Expand Down
34 changes: 34 additions & 0 deletions xee/_test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import json
import os

from google.auth import identity_pool


_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)
18 changes: 16 additions & 2 deletions xee/ext_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@
import xee

import ee
from google.auth import identity_pool
import json
import os
from google import auth

def _read_creds() -> identity_pool.Credentials:
with open(os.environ['GOOGLE_APPLICATION_CREDENTIALS']) as json_file:
json_config_info = json.loads(json_file.read())
credentials = identity_pool.Credentials.from_info(json_config_info)
return credentials.with_scopes(
['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/earthengine'])


def init_ee_for_tests():
ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com')
ee.Initialize(
credentials=xee._test_utils.read_identity_pool_creds(),
opt_url='https://earthengine-highvolume.googleapis.com',
)


class EEBackendArrayTest(absltest.TestCase):
Expand Down Expand Up @@ -337,7 +351,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 c349685

Please sign in to comment.