Skip to content

test: add test coverage for ee_initialize (#77)#2757

Open
schwehr wants to merge 3 commits intogee-community:masterfrom
schwehr:jules-3331853548565919833-195aa69b
Open

test: add test coverage for ee_initialize (#77)#2757
schwehr wants to merge 3 commits intogee-community:masterfrom
schwehr:jules-3331853548565919833-195aa69b

Conversation

@schwehr
Copy link
Copy Markdown
Collaborator

@schwehr schwehr commented Apr 20, 2026

Appends five new mock test cases to tests/test_coreutils.py covering all execution paths in geemap.coreutils.ee_initialize without making actual Earth Engine API calls. This includes testing an already authenticated state, initialization with a token via environment variable, execution in a Google Colab environment, default fallback notebook setup, and explicit custom argument initialization.

Appends five new mock test cases to `tests/test_coreutils.py` covering
all execution paths in `geemap.coreutils.ee_initialize` without making
actual Earth Engine API calls. This includes testing an already
authenticated state, initialization with a token via environment
variable, execution in a Google Colab environment, default fallback
notebook setup, and explicit custom argument initialization.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@schwehr
Copy link
Copy Markdown
Collaborator Author

schwehr commented Apr 28, 2026

@gemini Review the PR

@jdbcode
Copy link
Copy Markdown
Member

jdbcode commented Apr 28, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of unit tests for the ee_initialize function in tests/test_coreutils.py, covering various authentication scenarios including token-based initialization, Colab environments, and default notebook modes. The review feedback identifies a bug in the token-based initialization test where the project parameter is currently ignored and suggests refactoring the test class to use class-level mocks to reduce repetitive boilerplate code.

Comment thread tests/test_coreutils.py
Comment on lines +221 to +223
mock_initialize.assert_called_once_with(
credentials=mock_cred_instance, opt_url="http://test"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This assertion confirms that the project argument passed to ee_initialize is ignored when an EARTHENGINE_TOKEN is present. In geemap/coreutils.py, the project parameter is not passed to ee.Initialize in the token-based initialization path (lines 83-96). This appears to be a bug in the implementation, and the test should be updated to expect the project to be passed correctly.

Suggested change
mock_initialize.assert_called_once_with(
credentials=mock_cred_instance, opt_url="http://test"
)
mock_initialize.assert_called_once_with(
credentials=mock_cred_instance, project="test_proj", opt_url="http://test"
)

Comment thread tests/test_coreutils.py
Comment on lines +165 to +168
@mock.patch.object(coreutils.ee, "Initialize")
@mock.patch.object(coreutils.ee, "Authenticate")
@mock.patch.object(coreutils.ee.data, "setUserAgent")
@mock.patch.object(coreutils.ee.data, "_get_state")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These four mocks are repeated across all test methods in this class. To reduce boilerplate and improve maintainability, you can apply these patches at the class level. Note that when patching at the class level, the mock objects are passed as arguments to each test method after any method-level mocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants