Skip to content

Commit

Permalink
Auto reset eerepr in tests and allow unnecessary resets
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Nov 30, 2024
1 parent ca6b516 commit 185cef6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import ee
import eerepr

ee.Initialize()
eerepr.initialize()

display(ee.FeatureCollection("LARSE/GEDI/GEDI02_A_002_INDEX").limit(3))
```
Expand All @@ -65,5 +66,3 @@ display(ee.FeatureCollection("LARSE/GEDI/GEDI02_A_002_INDEX").limit(3))
## Caching

`eerepr` uses caching to improve performance. Server data will only be requested once for each unique Earth Engine object, and all subsequent requests will be retrieved from the cache until the Jupyter session is restarted.

When you import `eerepr`, it is automatically initialized with an unlimited cache size. You can manually set the number of unique objects to cache using `eerepr.initialize(max_cache_size=n)`. A value of `None` sets an unlimited cache while a value of `0` disables caching.
3 changes: 2 additions & 1 deletion eerepr/repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ def initialize(max_cache_size: int | None = None) -> None:
def reset():
"""Remove HTML repr methods added by eerepr to EE objects."""
for cls in reprs_set:
delattr(cls, REPR_HTML)
if hasattr(cls, REPR_HTML):
delattr(cls, REPR_HTML)
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import ee
import pytest

import eerepr


def pytest_sessionstart(session):
ee.Initialize()


@pytest.fixture(autouse=True)
def reset_eerepr():
"""Reset eerepr after each test to avoid inconsistent state."""
yield
eerepr.reset()


@pytest.fixture(scope="session")
def original_datadir():
"""Set the pytest-regressions directory."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reprs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ee
import pytest

import eerepr # noqa: F401
import eerepr
from eerepr.repr import _repr_html_


Expand Down

0 comments on commit 185cef6

Please sign in to comment.