Skip to content

Commit

Permalink
Issue #30 Centralize all run options in a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 22, 2024
1 parent f050b53 commit be3a573
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 57 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest_plugins = [
"openeo_test_suite.lib.backend_under_test",
"openeo_test_suite.lib.pytest_plugin",
]
28 changes: 6 additions & 22 deletions src/openeo_test_suite/lib/backend_under_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,24 @@ def get_backend_url(config: pytest.Config, required: bool = False) -> Union[str,
_backend_under_test: Union[None, _BackendUnderTest] = None


def pytest_addoption(parser):
"""Implementation of `pytest_addoption` hook."""
parser.addoption(
"-U",
"--openeo-backend-url",
action="store",
default=None,
help="The openEO backend URL to connect to.",
)


def pytest_configure(config):
"""Implementation of `pytest_configure` hook."""
def set_backend_under_test(backend: _BackendUnderTest):
global _backend_under_test
assert _backend_under_test is None
backend_url = get_backend_url(config)
if backend_url is None:
_backend_under_test = NoBackend()
else:
connection = openeo.connect(url=backend_url, auto_validate=False)
_backend_under_test = HttpBackend(connection=connection)
assert isinstance(backend, _BackendUnderTest)
_backend_under_test = backend


def _get_backend_under_test() -> _BackendUnderTest:
def get_backend_under_test() -> _BackendUnderTest:
global _backend_under_test
assert isinstance(_backend_under_test, _BackendUnderTest)
return _backend_under_test


@functools.lru_cache
def get_collection_ids() -> List[str]:
return _get_backend_under_test().list_collection_ids()
return get_backend_under_test().list_collection_ids()


@functools.lru_cache
def get_process_ids() -> List[str]:
return _get_backend_under_test().list_process_ids()
return get_backend_under_test().list_process_ids()
67 changes: 67 additions & 0 deletions src/openeo_test_suite/lib/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import argparse

import openeo

from openeo_test_suite.lib.backend_under_test import (
HttpBackend,
NoBackend,
get_backend_url,
set_backend_under_test,
)


def pytest_addoption(parser):
"""Implementation of `pytest_addoption` hook."""
parser.addoption(
"-U",
"--openeo-backend-url",
action="store",
default=None,
help="The openEO backend URL to connect to.",
)

parser.addoption(
"--process-levels",
action="store",
default="",
help="The openEO process profiles you want to test against, e.g. 'L1,L2,L2A'. Mutually exclusive with --processes.",
)
parser.addoption(
"--processes",
action="store",
default="",
help="The openEO processes you want to test against, e.g. 'apply,reduce_dimension'. Mutually exclusive with --process-levels.",
)

parser.addoption(
"--experimental",
type=bool,
action=argparse.BooleanOptionalAction,
default=False,
help="Run tests for experimental functionality or not. By default the tests will be skipped.",
)

parser.addoption(
"--runner",
action="store",
default="skip",
help="A specific test runner to use for individual process tests. If not provided, uses a default HTTP API runner.",
)

parser.addoption(
"--s2-collection",
action="store",
default=None,
help="The data collection to test against. It can be either a Sentinel-2 STAC Collection or the name of an openEO Sentinel-2 Collection provided by the back-end.",
)


def pytest_configure(config):
"""Implementation of `pytest_configure` hook."""
backend_url = get_backend_url(config)
if backend_url is None:
backend = NoBackend()
else:
connection = openeo.connect(url=backend_url, auto_validate=False)
backend = HttpBackend(connection=connection)
set_backend_under_test(backend)
34 changes: 0 additions & 34 deletions src/openeo_test_suite/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,6 @@
_log = logging.getLogger(__name__)


def pytest_addoption(parser):
parser.addoption(
"--experimental",
type=bool,
action=argparse.BooleanOptionalAction,
default=False,
help="Run tests for experimental functionality or not. By default the tests will be skipped.",
)
parser.addoption(
"--process-levels",
action="store",
default="",
help="The openEO process profiles you want to test against, e.g. 'L1,L2,L2A'. Mutually exclusive with --processes.",
)
parser.addoption(
"--processes",
action="store",
default="",
help="The openEO processes you want to test against, e.g. 'apply,reduce_dimension'. Mutually exclusive with --process-levels.",
)
parser.addoption(
"--runner",
action="store",
default="skip",
help="A specific test runner to use for individual process tests. If not provided, uses a default HTTP API runner.",
)
parser.addoption(
"--s2-collection",
action="store",
default=None,
help="The data collection to test against. It can be either a Sentinel-2 STAC Collection or the name of an openEO Sentinel-2 Collection provided by the back-end.",
)


@pytest.fixture(scope="session")
def skip_experimental(request) -> bool:
"""
Expand Down

0 comments on commit be3a573

Please sign in to comment.