From d54ef3d5eb0f789f6f98400973d1bfa615f305e5 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 6 Oct 2023 16:26:45 +0200 Subject: [PATCH] ioc/tests/StreamDevice: add ruff linter, fix most lints --- .../mock-server/mock_server/__init__.py | 60 +++++++++++-------- .../simple/mock-server/pyproject.toml | 3 + 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/ioc/tests/support/StreamDevice/simple/mock-server/mock_server/__init__.py b/ioc/tests/support/StreamDevice/simple/mock-server/mock_server/__init__.py index 0086e403..92fb10c6 100644 --- a/ioc/tests/support/StreamDevice/simple/mock-server/mock_server/__init__.py +++ b/ioc/tests/support/StreamDevice/simple/mock-server/mock_server/__init__.py @@ -1,21 +1,25 @@ -import sys +"""A simple server mocking an ASCII communication.""" +import sys -__version__ = '0.1.0' +__version__ = "0.1.0" -def log(*args, **kwargs): +def log(*args: str, **kwargs: str) -> None: + """Print a message to stderr.""" print(*args, file=sys.stderr, **kwargs) -def send(*args, **kwargs): - print(*args, end='\r\n', flush=True, **kwargs) +def send(*args: str, **kwargs: str) -> None: + """Send a message.""" + print(*args, end="\r\n", flush=True, **kwargs) -def main(): - log('received connection') +def main() -> None: + """Start the mock server.""" + log("received connection") - varfloat = 0. + varfloat = 0.0 scalc = "" while True: @@ -24,20 +28,23 @@ def main(): if not data: break - log('received command:', data) - - if data == 'FLOAT': - send('42.1234') - elif data == 'FLOAT_WITH_PREFIX': - send('VALUE: 69.1337') - elif data == 'ENUM': - send('TWO') - elif data.startswith('SET_VARFLOAT '): - varfloat = float(data.split(' ', maxsplit=1)[1]) - elif data == 'GET_VARFLOAT': + log("received command:", data) + + # TODO(minijackson): change that with a command-line parsing tool? + + if data == "FLOAT": + send("42.1234") + elif data == "FLOAT_WITH_PREFIX": + send("VALUE: 69.1337") + elif data == "ENUM": + send("TWO") + elif data.startswith("SET_VARFLOAT "): + varfloat = float(data.split(" ", maxsplit=1)[1]) + elif data == "GET_VARFLOAT": send(str(varfloat)) elif data == "REGEX_TITLE": - send(""" + send( + """ Hello, World! @@ -46,13 +53,14 @@ def main():

Hello, World!

-""") +""", + ) elif data == "REGEX_SUB": send("abcabcabcabc") - elif data.startswith('SET_SCALC '): - send('sent') - scalc = data.split(' ', maxsplit=1)[1] - elif data == 'GET_SCALC': + elif data.startswith("SET_SCALC "): + send("sent") + scalc = data.split(" ", maxsplit=1)[1] + elif data == "GET_SCALC": send(scalc) else: - log('unknown command') + log("unknown command") diff --git a/ioc/tests/support/StreamDevice/simple/mock-server/pyproject.toml b/ioc/tests/support/StreamDevice/simple/mock-server/pyproject.toml index 351e4b8c..d248b538 100644 --- a/ioc/tests/support/StreamDevice/simple/mock-server/pyproject.toml +++ b/ioc/tests/support/StreamDevice/simple/mock-server/pyproject.toml @@ -10,3 +10,6 @@ mock_server = "mock_server:main" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.ruff] +select = ["ALL"]