Skip to content

Commit 30ec4e4

Browse files
author
emmanuel
committed
test: use AST-based check for undefined _control attribute references
Addresses review feedback: a raw substring search could false-fail on comments, docstrings, or examples. The AST walk only flags actual self._control attribute access.
1 parent 36e0702 commit 30ec4e4

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

tests/test_mqtt_client_init.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,24 @@ async def test_configure_reservation_water_program_delegates(
858858
)
859859

860860
def test_no_references_to_undefined_control_attribute(self):
861-
"""No proxy may reference self._control (never assigned)."""
861+
"""No code may reference self._control (never assigned).
862+
863+
Uses an AST walk rather than a source substring search so that
864+
mentions in comments, docstrings, or examples cannot cause
865+
false failures — only actual attribute access counts.
866+
"""
867+
import ast
862868
import inspect
863869

864870
import nwp500.mqtt.client as client_module
865871

866-
source = inspect.getsource(client_module)
867-
assert "self._control." not in source
872+
tree = ast.parse(inspect.getsource(client_module))
873+
offenders = [
874+
node.lineno
875+
for node in ast.walk(tree)
876+
if isinstance(node, ast.Attribute)
877+
and node.attr == "_control"
878+
and isinstance(node.value, ast.Name)
879+
and node.value.id == "self"
880+
]
881+
assert offenders == []

0 commit comments

Comments
 (0)