Skip to content

Commit

Permalink
test: use pytest-gee for ee init (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Dec 17, 2023
2 parents 7277892 + 447d5b9 commit 807ae81
Show file tree
Hide file tree
Showing 3 changed files with 30,148 additions and 30,170 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test = [
"pytest-deadfixtures",
"httplib2",
"pytest-regressions>=2.4.3", # https://github.com/ESSS/pytest-regressions/issues/136
"pytest-gee",
]
doc = [
"sphinx>=6.2.1,<7", # https://github.com/pydata/pydata-sphinx-theme/issues/1404
Expand Down
31 changes: 4 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
"""Pytest session configuration."""

import os
from pathlib import Path
import pytest_gee

import ee
import httplib2


def pytest_configure() -> None:
"""Initialize earth engine according to the environment.
It will use the creddential file if the EARTHENGINE_TOKEN env variable exist.
Otherwise it use the simple Initialize command (asking the user to register if necessary).
"""
# only do the initialization if the credential are missing
if not ee.data._credentials:

# if the credentials token is asved in the environment use it
if "EARTHENGINE_TOKEN" in os.environ:

# write the token to the appropriate folder
ee_token = os.environ["EARTHENGINE_TOKEN"]
credential_folder_path = Path.home() / ".config" / "earthengine"
credential_folder_path.mkdir(parents=True, exist_ok=True)
credential_file_path = credential_folder_path / "credentials"
credential_file_path.write_text(ee_token)

# if the user is in local development the authentication should
# already be available
ee.Initialize(http_transport=httplib2.Http())
def pytest_configure():
"""Init GEE in the test environment."""
pytest_gee.init_ee_from_token()
Loading

0 comments on commit 807ae81

Please sign in to comment.