-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move logic to `lib` and plugin, with better (internal) test coverage - Replace fixture based approach in tests/processes/processing with filtering at test collection phase
- Loading branch information
Showing
7 changed files
with
216 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/openeo_test_suite/lib/internal-tests/test_process_selection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from openeo_test_suite.lib.process_selection import csv_to_list | ||
|
||
|
||
def test_csv_to_list(): | ||
assert csv_to_list() == [] | ||
assert csv_to_list("") == [] | ||
assert csv_to_list(" ") == [] | ||
assert csv_to_list(" , ") == [] | ||
assert csv_to_list("foo") == ["foo"] | ||
assert csv_to_list("foo,bar,baz") == ["foo", "bar", "baz"] | ||
assert csv_to_list(",foo,bar,baz,") == ["foo", "bar", "baz"] | ||
assert csv_to_list(" ,foo , bar, baz , ") == ["foo", "bar", "baz"] | ||
assert csv_to_list(" ,foo ,,, bar, , baz , ") == ["foo", "bar", "baz"] | ||
|
||
|
||
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 | ||
assert csv_to_list(" , ", none_on_empty=True) is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import Iterable, List, Optional, Union | ||
|
||
import pytest | ||
|
||
from openeo_test_suite.lib.process_registry import ProcessData, ProcessRegistry | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ProcessFilters: | ||
""" | ||
Container for process filters as specified through command line options | ||
`--processes`,`--process-level`, `--experimental` | ||
""" | ||
|
||
process_ids: Optional[List[str]] = None | ||
process_levels: Optional[List[str]] = None | ||
experimental: bool = False | ||
|
||
|
||
# Internal singleton pointing to active set of process filters | ||
# setup happens in `pytest_configure` hook | ||
_process_filters: Union[ProcessFilters, None] = None | ||
|
||
|
||
def set_process_selection_from_config(config: pytest.Config): | ||
"""Set up process selection from pytest config (CLI options).""" | ||
global _process_filters | ||
assert _process_filters is None | ||
_process_filters = ProcessFilters( | ||
process_ids=csv_to_list(config.getoption("--processes"), none_on_empty=True), | ||
process_levels=csv_to_list( | ||
config.getoption("--process-levels"), none_on_empty=True | ||
), | ||
experimental=config.getoption("--experimental"), | ||
) | ||
|
||
|
||
def get_selected_processes() -> Iterable[ProcessData]: | ||
""" | ||
Get effective list of processes extracted from the process registry | ||
with filtering based on command line options | ||
`--processes`,`--process-level`, `--experimental` | ||
""" | ||
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, | ||
) | ||
|
||
|
||
def csv_to_list( | ||
csv: Union[str, None] = None, *, separator: str = ",", none_on_empty: bool = False | ||
) -> Union[List[str], None]: | ||
""" | ||
Convert comma-separated string to list of strings, | ||
properly taking care of trailing whitespace, empty items, ... | ||
""" | ||
# TODO: options to disable stripping, or to allow empty items? | ||
items = [item.strip() for item in (csv or "").split(separator) if item.strip()] | ||
if not items and none_on_empty: | ||
return None | ||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters