Skip to content

Commit d69550e

Browse files
committed
sonarqube issues
1 parent 2685d5a commit d69550e

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

agents/matlab/matlab_agent/src/comm/rabbitmq/message_handler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def validate_sim_type(cls, v):
5757
@model_validator(mode='after')
5858
def check_stream_source_for_interactive(self):
5959
"""
60-
Validate that 'inputs.stream_source' is provided for interactive simulations.
60+
Validate that 'inputs.stream_source' is provided
61+
for interactive simulations.
6162
"""
62-
if self.type == 'interactive':
63-
if not self.inputs.stream_source:
64-
raise ValueError(
65-
"For 'interactive' simulations you must provide "
66-
"'inputs.stream_source'"
67-
)
63+
if self.type == 'interactive' and not self.inputs.stream_source:
64+
raise ValueError(
65+
"For 'interactive' simulations you must provide "
66+
"'inputs.stream_source'"
67+
)
6868
return self
6969

7070

agents/matlab/matlab_agent/src/core/interactive.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _parse_frame(body: bytes) -> Dict[str, Any]:
3434
"""Decode a YAML frame received from RabbitMQ."""
3535
try:
3636
return yaml.safe_load(body)
37-
except Exception as exc: # pragma: no cover - logging only
37+
except yaml.YAMLError as exc: # pragma: no cover - logging only
3838
logger.error("[INTERACTIVE] Bad frame: %s", exc)
3939
return {}
4040

@@ -243,14 +243,14 @@ def run(self, pm: PerformanceMonitor, msg_dict: Dict[str, Any]) -> None:
243243
if self.out_srv.matlab_proc and self.out_srv.matlab_proc.poll() is not None:
244244
logger.debug("[INTERACTIVE] MATLAB process ended, stopping loop")
245245
break
246-
method, properties, body = ch.basic_get(
246+
method, _ , body = ch.basic_get(
247247
queue=qname, auto_ack=True)
248248
while method:
249249
frame = _parse_frame(body)
250250
if frame:
251251
# Send the inputs to MATLAB
252252
self.in_srv.send(self._only_inputs(frame))
253-
method, properties, body = ch.basic_get(
253+
method, _ , body = ch.basic_get(
254254
queue=qname, auto_ack=True)
255255

256256
# Receive Responses from MATLAB
@@ -308,8 +308,8 @@ def handle_interactive_simulation(
308308
try:
309309
controller.start(pm)
310310
controller.run(pm, msg_dict)
311-
except (KeyError, ValueError, RuntimeError) as exc: # pragma: no cover - handled errors
312-
logger.error("[INTERACTIVE] Fatal: %s", exc)
311+
except (KeyError, ValueError) as exc: # Handle specific known errors
312+
logger.error("[INTERACTIVE] Known error: %s", exc)
313313
rabbitmq_manager.send_result(
314314
source,
315315
create_response(

agents/matlab/matlab_agent/test/unit/test_main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import logging
1212
from pathlib import Path
13-
from unittest.mock import MagicMock, patch, mock_open, call
13+
from unittest.mock import MagicMock, patch, mock_open
1414
import pytest
1515
from click.testing import CliRunner
1616

@@ -105,7 +105,7 @@ def test_generate_project_flag(self, cli_runner):
105105
# Test main function with config file
106106
def test_main_with_config_file(self, cli_runner, mock_dependencies):
107107
"""Test main function with explicitly provided config file."""
108-
mock_matlab_agent, mock_setup_logger, mock_load_config, mock_logger = mock_dependencies
108+
mock_matlab_agent, _ , mock_load_config, _ = mock_dependencies
109109

110110
mock_load_config.return_value = {
111111
'agent': {'agent_id': 'custom_agent'},
@@ -129,7 +129,7 @@ def test_main_with_config_file(self, cli_runner, mock_dependencies):
129129
def test_main_without_config_file_exists(
130130
self, cli_runner, mock_dependencies, default_config):
131131
"""Test main function when config.yaml exists in current directory."""
132-
mock_matlab_agent, mock_setup_logger, mock_load_config, mock_logger = mock_dependencies
132+
mock_matlab_agent, _, mock_load_config, _ = mock_dependencies
133133

134134
with patch('pathlib.Path.exists', return_value=True):
135135
mock_load_config.return_value = default_config
@@ -261,7 +261,7 @@ def test_generate_default_config_success_importlib(self):
261261
with patch('pathlib.Path.cwd', return_value=test_dir), \
262262
patch('pathlib.Path.exists', return_value=False), \
263263
patch('importlib.resources.files') as mock_files, \
264-
patch('builtins.open', mock_open()) as mock_file:
264+
patch('builtins.open', mock_open()) as _:
265265

266266
# Mock importlib.resources.files behavior
267267
mock_resource = MagicMock()
@@ -297,7 +297,7 @@ def test_generate_default_config_fallback_pkg_resources(self):
297297
patch('pathlib.Path.exists', return_value=False), \
298298
patch('importlib.resources.files', side_effect=ImportError()), \
299299
patch.dict('sys.modules', {'pkg_resources': mock_pkg_resources}), \
300-
patch('builtins.open', mock_open()) as mock_file, \
300+
patch('builtins.open', mock_open()) as _, \
301301
patch('builtins.print') as mock_print:
302302

303303
generate_default_config()
@@ -368,7 +368,7 @@ def test_generate_config_with_attribute_error_fallback(self):
368368
patch('pathlib.Path.exists', return_value=False), \
369369
patch('importlib.resources.files', side_effect=AttributeError()), \
370370
patch.dict('sys.modules', {'pkg_resources': mock_pkg_resources}), \
371-
patch('builtins.open', mock_open()) as mock_file, \
371+
patch('builtins.open', mock_open()) as _, \
372372
patch('builtins.print') as mock_print:
373373

374374
generate_default_config()
@@ -381,7 +381,7 @@ def test_generate_default_project_success_importlib(self):
381381
"""Test successful project generation using importlib.resources."""
382382
with patch('pathlib.Path.exists', return_value=False), \
383383
patch('importlib.resources.files') as mock_files, \
384-
patch('builtins.open', mock_open()) as mock_file, \
384+
patch('builtins.open', mock_open()) as _, \
385385
patch('builtins.print') as mock_print:
386386

387387
# Mock importlib.resources.files behavior
@@ -506,7 +506,7 @@ def test_cli_help_option(self, cli_runner):
506506

507507
def test_cli_short_config_option(self, cli_runner, mock_dependencies):
508508
"""Test short form of config option (-c)."""
509-
mock_matlab_agent, mock_setup_logger, mock_load_config, mock_logger = mock_dependencies
509+
_, _, mock_load_config, _ = mock_dependencies
510510

511511
mock_load_config.return_value = {
512512
'agent': {'agent_id': 'test_agent'},
@@ -534,7 +534,7 @@ def test_multiple_flags_priority(self, cli_runner):
534534

535535
def test_broker_type_hardcoded(self, cli_runner, mock_dependencies):
536536
"""Test that broker_type is hardcoded to 'rabbitmq'."""
537-
mock_matlab_agent, mock_setup_logger, mock_load_config, mock_logger = mock_dependencies
537+
mock_matlab_agent, _, mock_load_config, _ = mock_dependencies
538538

539539
mock_load_config.return_value = {
540540
'agent': {'agent_id': 'test_agent'},

agents/matlab/matlab_agent/test/unit/test_rabbitmq_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def test_initialization(self, mock_connection, mock_config, agent_id):
9494

9595
def test_register_message_handler(self, rabbitmq_manager):
9696
def handler(channel, method, properties, body):
97+
""" Dummy handler for testing. """
98+
# This function is intentionally left empty to serve as a placeholder for testing.
9799
pass
98100
rabbitmq_manager.register_message_handler(handler)
99101
assert rabbitmq_manager.message_handler is handler

agents/matlab/matlab_agent/test/unit/test_streaming.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test suite for streaming functionality."""
22

3-
# pylint: disable=missing-module-docstring, missing-class-docstring,
4-
# missing-function-docstring, too-many-positional-arguments
3+
4+
# pylint: disable=too-many-positional-arguments
55

66

77
import socket
@@ -373,7 +373,7 @@ def test_handle_streaming_simulation_missing_fields(
373373
{'simulation': {'foo': 'bar'}}, # Missing data
374374
'test_queue',
375375
mock_rabbit_client,
376-
None, # path_simulation not specified
376+
Path("test_path"),
377377
response_templates,
378378
tcp_settings
379379
)

0 commit comments

Comments
 (0)