Skip to content

Commit

Permalink
Fix caching issue with get_selected_processes()
Browse files Browse the repository at this point in the history
a non-reusable generator was being cached instead of a cachable concrete result (list)

related to PR #44
  • Loading branch information
soxofaan committed Feb 1, 2024
1 parent 2f560c8 commit 88151b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from openeo_test_suite.lib.process_selection import csv_to_list
from openeo_test_suite.lib.process_selection import csv_to_list, get_selected_processes


def test_csv_to_list():
Expand All @@ -18,3 +18,12 @@ def test_csv_to_list_none_on_empty():
assert csv_to_list("", none_on_empty=True) is None
assert csv_to_list(" ", none_on_empty=True) is None
assert csv_to_list(" , ", none_on_empty=True) is None


def test_get_selected_processes_caching():
processes = get_selected_processes()
assert len(processes) > 0

processes2 = get_selected_processes()
assert processes2 is processes
assert len(processes2) > 0
2 changes: 1 addition & 1 deletion src/openeo_test_suite/lib/process_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_processes_filtered(
process_ids: Optional[List[str]] = None,
process_levels: Optional[List[str]] = None,
experimental: bool = False,
) -> Iterable[ProcessData]:
) -> Iterator[ProcessData]:
"""
Collect processes matching with additional filtering:
Expand Down
12 changes: 7 additions & 5 deletions src/openeo_test_suite/lib/process_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def set_process_selection_from_config(config: pytest.Config):

# TODO: more structural/testable solution for get_selected_processes related caching?
@functools.lru_cache()
def get_selected_processes() -> Iterable[ProcessData]:
def get_selected_processes() -> List[ProcessData]:
"""
Get effective list of processes extracted from the process registry
with filtering based on command line options
Expand All @@ -51,10 +51,12 @@ def get_selected_processes() -> Iterable[ProcessData]:
global _process_filters
assert isinstance(_process_filters, ProcessFilters)

return ProcessRegistry().get_processes_filtered(
process_ids=_process_filters.process_ids,
process_levels=_process_filters.process_levels,
experimental=_process_filters.experimental,
return list(
ProcessRegistry().get_processes_filtered(
process_ids=_process_filters.process_ids,
process_levels=_process_filters.process_levels,
experimental=_process_filters.experimental,
)
)


Expand Down

0 comments on commit 88151b9

Please sign in to comment.