Skip to content

Commit f428f9f

Browse files
committed
fix: address SonarCloud code smells in tests
- Add docstrings to empty async on_enter_state methods (S1186) - Use await asyncio.sleep(0) in async test hooks to satisfy S7503
1 parent affcf67 commit f428f9f

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

tests/test_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def cond_false(self):
116116
return False
117117

118118
async def on_enter_state(self, target):
119-
pass
119+
"""Async callback to ensure the SM uses AsyncEngine."""
120120

121121

122122
async def test_async_condition_not(recwarn):

tests/test_copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class AsyncTrafficLightMachine(StateMachine):
192192
cycle = green.to(yellow) | yellow.to(red) | red.to(green)
193193

194194
async def on_enter_state(self, target):
195-
pass
195+
"""Async callback to ensure the SM uses AsyncEngine."""
196196

197197

198198
def test_copy_async_statemachine_before_activation(copy_method):

tests/test_spec_parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,11 @@ def async_variable_hook(var_name):
257257
"val_20": 20,
258258
}
259259

260+
value = values.get(var_name, False)
261+
260262
async def decorated(*args, **kwargs):
261-
return values.get(var_name, False)
263+
await asyncio.sleep(0)
264+
return value
262265

263266
decorated.__name__ = var_name
264267
return decorated
@@ -301,9 +304,11 @@ def mixed_variable_hook(var_name):
301304
async_values = {"async_true": True, "async_false": False, "async_20": 20}
302305

303306
if var_name in async_values:
307+
value = async_values[var_name]
304308

305309
async def async_decorated(*args, **kwargs):
306-
return async_values[var_name]
310+
await asyncio.sleep(0)
311+
return value
307312

308313
async_decorated.__name__ = var_name
309314
return async_decorated

0 commit comments

Comments
 (0)