test: add test coverage for ee_initialize (#77)#2757
test: add test coverage for ee_initialize (#77)#2757schwehr wants to merge 3 commits intogee-community:masterfrom
Conversation
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>
|
@gemini Review the PR |
|
/gemini review |
There was a problem hiding this comment.
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.
| mock_initialize.assert_called_once_with( | ||
| credentials=mock_cred_instance, opt_url="http://test" | ||
| ) |
There was a problem hiding this comment.
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.
| 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" | |
| ) |
| @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") |
There was a problem hiding this comment.
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.
Appends five new mock test cases to
tests/test_coreutils.pycovering all execution paths ingeemap.coreutils.ee_initializewithout 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.