diff --git a/src/coastseg/common.py b/src/coastseg/common.py index efa0f6a2..552f6cb7 100644 --- a/src/coastseg/common.py +++ b/src/coastseg/common.py @@ -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. @@ -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. diff --git a/tests/test_common.py b/tests/test_common.py index c7cfc933..d924f1c8 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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():