dScriptModule 3.5.0__tar.gz → 3.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dScriptModule
3
- Version: 3.5.0
3
+ Version: 3.5.1
4
4
  Summary: Home Assistant ready python module for dScript boards (by Robot-Electronics / Devantech Ltd.) with CUSTOM app firmware
5
5
  Home-page: https://github.com/mk-maddin/dScriptModule
6
6
  Author: Martin Kraemer
@@ -1,4 +1,4 @@
1
- __version__ = "3.5.0"
1
+ __version__ = "3.5.1"
2
2
 
3
3
  from .dScriptObject import *
4
4
  from .dScriptServer import *
@@ -704,7 +704,7 @@ class dScriptBoard(dScriptObject):
704
704
  databytes=self._ToDataBytes(data)
705
705
  return self.__CheckSet(self._ToDataBytes(data)[0])
706
706
  except Exception as e:
707
- _LOGGER.error("dScriptBoard - %s: async_SetLight failed: %s (%s.%s)", str(e), e.__class__.__module__, type(e).__name__)
707
+ _LOGGER.error("dScriptBoard - %s: async_SetLight failed: %s (%s.%s)", self.friendlyname, str(e), e.__class__.__module__, type(e).__name__)
708
708
 
709
709
  '''Execute the SH, SetShutter command to define a shutter status'''
710
710
  def SetShutter(self,identifier,state) -> None | bool:
@@ -9,4 +9,5 @@ dScriptModule/dScriptObject.py
9
9
  dScriptModule/dScriptServer.py
10
10
  dScriptModule/dScriptVirtualBoard.py
11
11
  tests/test_board.py
12
+ tests/test_logging_calls.py
12
13
  tests/test_server_events.py
@@ -0,0 +1,31 @@
1
+ """Every logging call must have as many arguments as its format string has placeholders.
2
+
3
+ A mismatch only shows up when the message is formatted (e.g. with debug logging enabled) - pytest then raises,
4
+ in production the log line is lost. This already broke board setup once (10 placeholders, 9 arguments).
5
+ """
6
+ import ast
7
+ import os
8
+ import re
9
+
10
+ ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
11
+ LEVELS = {"debug", "info", "warning", "error", "exception", "critical"}
12
+ PLACEHOLDER = re.compile(r"%(?!%)[-#0 +]*\d*(?:\.\d+)?[sdifrx]")
13
+
14
+
15
+ def test_logging_placeholders_match_arguments():
16
+ mismatches = []
17
+ for base, _dirs, files in os.walk(os.path.join(ROOT, "dScriptModule")):
18
+ for name in files:
19
+ if not name.endswith(".py"):
20
+ continue
21
+ path = os.path.join(base, name)
22
+ with open(path, encoding="utf-8") as fh:
23
+ tree = ast.parse(fh.read(), path)
24
+ for node in ast.walk(tree):
25
+ if (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr in LEVELS
26
+ and node.args and isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str)):
27
+ need = len(PLACEHOLDER.findall(node.args[0].value))
28
+ have = len(node.args) - 1
29
+ if need != have:
30
+ mismatches.append("%s:%s: %s placeholders, %s arguments" % (os.path.relpath(path, ROOT), node.lineno, need, have))
31
+ assert mismatches == []
File without changes
File without changes
File without changes
File without changes
File without changes