Skip to content

Commit

Permalink
ioc/tests/StreamDevice: add ruff linter, fix most lints
Browse files Browse the repository at this point in the history
  • Loading branch information
minijackson committed Oct 6, 2023
1 parent f86381e commit d54ef3d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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("""<!DOCTYPE html>
send(
"""<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
Expand All @@ -46,13 +53,14 @@ def main():
<p>Hello, World!</p>
</body>
</html>
""")
""",
)
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")
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit d54ef3d

Please sign in to comment.