From fa7415c35e0798769a415b9e63a05daf9a444f6b Mon Sep 17 00:00:00 2001 From: Tomas Nilsson Date: Fri, 13 Sep 2024 13:44:10 +0000 Subject: [PATCH] chore(grpc-asyncio): add live broker smoketest --- python/README.md | 17 ++++++++--------- python/remotivelabs-broker/conftest.py | 16 ++++++++++++++++ python/remotivelabs-broker/pyproject.toml | 9 +++------ .../{test_live.py => test_smoke_system.py} | 19 +++++++------------ 4 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 python/remotivelabs-broker/conftest.py rename python/remotivelabs-broker/tests/system/{test_live.py => test_smoke_system.py} (86%) diff --git a/python/README.md b/python/README.md index 6fb7684..f94f0c1 100644 --- a/python/README.md +++ b/python/README.md @@ -9,7 +9,7 @@ Published to PyPI on [https://pypi.org/project/remotivelabs-broker/](https://pyp Prerequisites: ```bash -# Install poetry (and optionally poe plugin) +# Install poetry (and optionally poe plugin to simplify poetry command execution) pipx install poetry poetry self add 'poethepoet[poetry_plugin]' ``` @@ -25,14 +25,14 @@ poetry install # Build the library (output in dist/) poetry build -# test local (local test does not require a running broker) -poetry poe test-local +# Check (test, lint, check types) +poetry poe check -# test server (server test requires a running broker) -poetry poe test-server +# run standard test suite +poetry run pytest -# test all -poetry poe test +# run tests against running broker +poetry run pytest -m server --broker ``` If you need to (re)generate protobuf stubs, see [Building](#building). @@ -42,8 +42,7 @@ If you need to (re)generate protobuf stubs, see [Building](#building). Building the complete package, including protobuf stubs and documentation, is done using a docker container: ```bash -cd python/remotivelabs-broker -./docker-build.sh +./python/remotivelabs-broker/docker-build.sh ``` ## Versioning diff --git a/python/remotivelabs-broker/conftest.py b/python/remotivelabs-broker/conftest.py new file mode 100644 index 0000000..07a740e --- /dev/null +++ b/python/remotivelabs-broker/conftest.py @@ -0,0 +1,16 @@ +import pytest + + +def pytest_addoption(parser: pytest.Parser) -> None: + parser.addoption( + "--broker", + action="store", + default="http://localhost:50051", + type=str, + help="Broker URI to run test against.", + ) + + +@pytest.fixture +def broker_url(request): + return request.config.getoption("--broker") diff --git a/python/remotivelabs-broker/pyproject.toml b/python/remotivelabs-broker/pyproject.toml index c8a6bea..e804a39 100644 --- a/python/remotivelabs-broker/pyproject.toml +++ b/python/remotivelabs-broker/pyproject.toml @@ -55,13 +55,10 @@ json-schema-for-humans = "^1.0" [tool.poe.tasks] test-server = "pytest -m server --cov=remotivelabs.broker" test = "pytest --cov=remotivelabs.broker" -format = [{ cmd = "ruff check --select I --fix" }, { cmd = "ruff format" }] -format-check = [ - { cmd = "ruff check --select I" }, - { cmd = "ruff format --check --diff" }, -] +format = [{ cmd = "ruff check --fix ." }, { cmd = "ruff format ." }] +lint = [{ cmd = "ruff check ." }, { cmd = "ruff format --check --diff ." }] mypy-check = [{ cmd = "mypy remotivelabs/broker" }, { cmd = "mypy tests" }] -check = ["test", "format-check", "mypy-check"] +check = ["test", "lint", "mypy-check"] [tool.ruff] line-length = 140 diff --git a/python/remotivelabs-broker/tests/system/test_live.py b/python/remotivelabs-broker/tests/system/test_smoke_system.py similarity index 86% rename from python/remotivelabs-broker/tests/system/test_live.py rename to python/remotivelabs-broker/tests/system/test_smoke_system.py index 5cf178f..510610c 100644 --- a/python/remotivelabs-broker/tests/system/test_live.py +++ b/python/remotivelabs-broker/tests/system/test_smoke_system.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging import pytest @@ -5,26 +7,18 @@ import remotivelabs.broker as br import remotivelabs.broker.sync as br_sync -# Warning these tests require a RemotiveBroker up and running -# server address: -_SERVER_URL = "http://127.0.0.1:50051" -_SERVER_APIKEY = None - class Connection: - def __init__(self): - self.channel = br_sync.create_channel(_SERVER_URL, _SERVER_APIKEY) - self.network_stub = br.network_api_pb2_grpc.NetworkServiceStub(self.channel) + def __init__(self, url: str, api_key: str | None = None): + self.channel = br_sync.create_channel(url, api_key) self.system_stub = br.system_api_pb2_grpc.SystemServiceStub(self.channel) -# Setup broker with predefined settings @pytest.fixture(name="broker_connection") -def fixture_broker_connection(): - return Connection() +def fixture_broker_connection(broker_url): + return Connection(broker_url) -# Setup broker configured for testing @pytest.fixture(name="broker_configured") def fixture_broker_configured(broker_connection): br_sync.upload_folder(broker_connection.system_stub, "tests/fixtures/configs/udp") @@ -52,6 +46,7 @@ def test_meta_fields(broker_configured): assert meta_speed.getSize() == 16 assert meta_speed.getIsRaw() is False assert meta_parent.getIsRaw() is True + assert meta_speed.getFactor() == 1.0 assert meta_speed.getOffset() == 0.0 assert meta_speed.getSenders() == ["ECUA"]