Skip to content

Commit

Permalink
fix broken tests for GEE authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Jul 10, 2024
1 parent 0d8e4f1 commit 6830914
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/coastseg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def initialize_gee(
# Authenticate and initialize
authenticate_and_initialize(print_mode, force, auth_args, kwargs)


def authenticate_and_initialize(print_mode: bool, force: bool, auth_args: dict, kwargs: dict, attempt: int = 1, max_attempts: int = 2):
"""
Handles the authentication and initialization of Google Earth Engine.
Expand Down Expand Up @@ -490,14 +491,13 @@ def authenticate_and_initialize(print_mode: bool, force: bool, auth_args: dict,
else:
print(f"An error occurred: {error_message}\n")

# Re-attempt authentication only if not already attempted and attempts are less than max_attempts
# Re-attempt authentication only if attempts are less than max_attempts
if attempt < max_attempts:
print(f"Re-attempting authentication (Attempt {attempt + 1}/{max_attempts})...\n")
authenticate_and_initialize(print_mode, True, auth_args, kwargs, attempt + 1, max_attempts) # Force re-authentication on retry
else:
raise Exception(f"Failed to initialize Google Earth Engine after {attempt} attempts: {error_message}")


def create_new_config(roi_ids: list, settings: dict, roi_settings: dict) -> dict:
"""
Creates a new configuration dictionary by combining the given settings and ROI settings.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def test_authenticate_and_initialize_max_attempts():
with pytest.raises(Exception) as excinfo:
common.authenticate_and_initialize(print_mode=True, force=False, auth_args={}, kwargs={})

assert "Failed to initialize Google Earth Engine after 3 attempts" in str(excinfo.value)
assert mock_authenticate.call_count == 3
assert mock_initialize.call_count == 3
assert "Failed to initialize Google Earth Engine after 2 attempts" in str(excinfo.value)
assert mock_authenticate.call_count == 2
assert mock_initialize.call_count == 2


def test_order_linestrings_gdf_empty():
Expand Down

0 comments on commit 6830914

Please sign in to comment.