-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use pytest-gee for ee init (#46)
- Loading branch information
Showing
3 changed files
with
30,148 additions
and
30,170 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 |
---|---|---|
@@ -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() |
Oops, something went wrong.