Skip to content

Commit

Permalink
Fix several code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mhthies committed Dec 3, 2023
1 parent f7d5b94 commit 682d659
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shc/data_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class WritableDataLogVariable(DataLogVariable[T], Writable[T], Generic[T], metac
:meth:`retrieve_log`, as usual for `DataLogVariables`. In addition, derived classes shall allow to set override
`external_updates` attribute for each instance (via an __init__ parameter) to disable push updates for data logs
which are updated externally.
:ivar external_updates: Specifies, whether SHC-external updates to the data log are expected. This effectively
will make this class unsubscribable (because we cannot guarantee to reproduce a consistent log through push
updates), so attached `LiveDataLogView` will fall back to periodic polling of the log.
Expand Down
2 changes: 1 addition & 1 deletion shc/interfaces/in_memory_data_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InMemoryDataLogVariable(Writable[T], DataLogVariable[T], Readable[T], Gene
restart of the SHC application. It's also fine for demonstration purposes (see ui_logging_showcase.py in the
examples/ directory).
:param type\_: Value type of this `connectable` object (and as a `DataLogVariable`)
:param type\\_: Value type of this `connectable` object (and as a `DataLogVariable`)
:param keep: timespan for which to keep the values. Older values will be deleted upon the next `write` to the
object.
"""
Expand Down
3 changes: 1 addition & 2 deletions shc/interfaces/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MySQLConnector(ReadableStatusInterface):
);
For data logging of all value types that are derived from `int` (incl. `bool`), `float` or `str`, the respective
`value\_` column is used. This includes Enum types with a value base type in any of those. Otherwise, the value is
`value\\_` column is used. This includes Enum types with a value base type in any of those. Otherwise, the value is
JSON-encoded, using SHC's generic JSON encoding/decoding system from the :mod:`shc.conversion`, and stored in the
`value_str` column.
Expand Down Expand Up @@ -143,7 +143,6 @@ def persistence_variable(self, type_: Type[T], name: str) -> "MySQLPersistenceVa
self.persistence_variables[name] = variable
return variable


def __repr__(self) -> str:
return "{}({})".format(self.__class__.__name__, {k: v for k, v in self.connect_args.items()
if k in ('host', 'db', 'port', 'unix_socket')})
Expand Down
1 change: 1 addition & 0 deletions shc/web/log_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ..base import T
from .interface import WebPageItem, WebUIConnector, jinja_env


class LogListDataSpec(NamedTuple, Generic[T]):
"""Specification of one data log source and the formatting of its datapoints within a :class:`LogListWidget`"""
#: The `DataLogVariable` (i.e. logging database connector) to retrieve the recent datapoints and updates from
Expand Down
7 changes: 4 additions & 3 deletions test/interfaces/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse_mysql_url(url: str) -> Dict[str, Any]:
except ValueError as e:
print(f"Could not parse MySQL connection URL: {e}")
if parts.scheme != "mysql":
print(f"Could not parse MySQL connection URL: Schema is not 'mysql'")
print("Could not parse MySQL connection URL: Schema is not 'mysql'")
result: Dict[str, Any] = {'user': parts.username, 'password': parts.password, 'db': parts.path.lstrip("/")}
if parts.netloc.startswith("/"):
result["unix_socket"] = parts.hostname
Expand All @@ -37,7 +37,7 @@ def parse_mysql_url(url: str) -> Dict[str, Any]:
if MYSQL_URL is not None:
MYSQL_ARGS = parse_mysql_url(MYSQL_URL)
# pymysql uses slightly different args than aiomysql
PYMYSQL_ARGS = dict(MYSQL_ARGS, database= MYSQL_ARGS["db"])
PYMYSQL_ARGS = dict(MYSQL_ARGS, database=MYSQL_ARGS["db"])
del PYMYSQL_ARGS["db"]
else:
MYSQL_ARGS = {}
Expand All @@ -57,7 +57,8 @@ class MySQLTest(AbstractLoggingTest):
do_subscribe_tests = True

def setUp(self) -> None:
self._run_mysql_sync(["""
self._run_mysql_sync([
"""
CREATE TABLE `log` (
name VARCHAR(256) NOT NULL,
ts DATETIME(6) NOT NULL,
Expand Down
4 changes: 3 additions & 1 deletion test/test_data_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, Tuple, Generic, Type, Iterable, Any, Sequence, Union, Dict, Optional

import shc.data_logging
from shc.base import T, UninitializedError, Readable, Writable
from shc.base import T, UninitializedError, Readable
from ._helper import async_test, ClockMock

time_series_1 = [
Expand Down Expand Up @@ -465,6 +465,7 @@ async def test_push(self) -> None:
view = ExampleLiveDataLogView(log_var,
interval=datetime.timedelta(seconds=30),
update_interval=datetime.timedelta(seconds=2))

async def pusher():
for t, v in time_series_1:
await asyncio.sleep(max(0.0, (t - datetime.datetime.now().astimezone()).total_seconds()))
Expand All @@ -491,6 +492,7 @@ async def test_push_two_clients(self) -> None:
view = ExampleLiveDataLogView(log_var,
interval=datetime.timedelta(seconds=30),
update_interval=datetime.timedelta(seconds=10))

async def pusher():
for t, v in time_series_1:
await asyncio.sleep(max(0.0, (t - datetime.datetime.now().astimezone()).total_seconds()))
Expand Down

0 comments on commit 682d659

Please sign in to comment.