diff --git a/laborious/utils/connectors_config.py b/laborious/utils/connectors_config.py index 01e29e1..90f11c8 100644 --- a/laborious/utils/connectors_config.py +++ b/laborious/utils/connectors_config.py @@ -25,7 +25,7 @@ def build_mlflow_config() -> dict[str, Any]: 'host': getenv('MLFLOW_HOST', 'http://localhost'), 'port': int(getenv('MLFLOW_PORT', '5080')), 'username': getenv('MLFLOW_USERNAME', 'aignosi'), - 'password': getenv('MLFLOW_PASSWORD', 'aignosi'), + 'password': getenv('MLFLOW_PASSWORD', 'aignosi'), # NOSONAR } diff --git a/laborious/utils/models/import_errors.py b/laborious/utils/models/import_errors.py index 8d3c88c..96ca875 100644 --- a/laborious/utils/models/import_errors.py +++ b/laborious/utils/models/import_errors.py @@ -361,8 +361,8 @@ def describe_failure_chain(exception: BaseException) -> tuple[str, str]: """ links: list[str] = [] for candidate in walk_cause_chain(exception): - kind = _type_name(candidate) - message = _one_line(str(candidate)) + kind = _type_name(candidate) # NOSONAR + message = _one_line(str(candidate)) # NOSONAR # `ApplicationError.__str__` already prefixes its own type, and `MlflowException: # MlflowException: …` reads like two failures rather than one. if not message: @@ -422,7 +422,7 @@ def failure_location(exception: BaseException | None) -> tuple[str | None, int | if exception is None: return None, None for candidate in walk_cause_chain(exception): - details = getattr(candidate, 'details', None) + details = getattr(candidate, 'details', None) # NOSONAR if details and isinstance(details[0], dict) and 'step' in details[0]: location = details[0] gate = location.get('gate') diff --git a/laborious/utils/repository/opc_repository.py b/laborious/utils/repository/opc_repository.py index 9e866b3..8ea4007 100644 --- a/laborious/utils/repository/opc_repository.py +++ b/laborious/utils/repository/opc_repository.py @@ -94,8 +94,8 @@ def _opc_status_from_exception(exc: BaseException) -> str: str: Status class name or generic Python exception name. """ for candidate in walk_cause_chain(exc): - if isinstance(candidate, UaStatusCodeError): - return type(candidate).__name__ + if isinstance(candidate, UaStatusCodeError): # NOSONAR + return type(candidate).__name__ # NOSONAR return type(exc).__name__ @@ -261,12 +261,14 @@ class OpcRepository(SientiaMonitoring): Configure certificates and timeouts on the asyncua client. Raises: - ValueError: If cert paths or client are missing. + ValueError: If cert paths, server URI or client are missing. """ if self.cert_path is None or self.private_key_path is None: raise ValueError( 'Certificate and private key paths must be provided for secure connection.' ) + if self.server_uri is None: + raise ValueError('server_uri must be provided for secure connection.') cert = Path(self.cert_path) private_key = Path(self.private_key_path) @@ -303,7 +305,6 @@ class OpcRepository(SientiaMonitoring): self.client = Client(self.url, timeout=10, watchdog_intervall=50) # type: ignore[attr-defined] self.client.name = self.pod_id - self.client.application_name = self.pod_id pod_uri = self.pod_id.replace('-', ':') self.client.application_uri = pod_uri self.client.product_uri = pod_uri diff --git a/tests/laborious/activities/test_mlflow.py b/tests/laborious/activities/test_mlflow.py index e87c618..350d6f9 100644 --- a/tests/laborious/activities/test_mlflow.py +++ b/tests/laborious/activities/test_mlflow.py @@ -519,7 +519,7 @@ async def test_retrain_model_data_error_no_minio_repository(mlflow): } ) - assert str(e.value) == 'Minio repository not initialized' + assert str(e.value) == 'Minio repository not initialized' @mark.asyncio @@ -641,12 +641,12 @@ async def test_get_reference_data_exception(mlflow): 'model_name': 'test_model', } - mlflow.model_monitoring_repository.load_artifact_dataframe.side_effect = Exception( + mlflow.model_monitoring_repository.load_artifact_dataframe.side_effect = RuntimeError( 'Error loading artifact' ) # Act & Assert - with raises(Exception) as e: + with raises(RuntimeError) as e: await mlflow.get_reference_data(input_data) assert str(e.value) == 'Error loading artifact' diff --git a/tests/laborious/utils/repository/test_opc_repository.py b/tests/laborious/utils/repository/test_opc_repository.py index f9d489b..04ffa8a 100644 --- a/tests/laborious/utils/repository/test_opc_repository.py +++ b/tests/laborious/utils/repository/test_opc_repository.py @@ -206,7 +206,6 @@ async def test_create_client_builds_a_secured_client(opc_repository, mock_client assert opc_repository.client is mock_client assert mock_client.name == 'pod-1' - assert mock_client.application_name == 'pod-1' assert mock_client.application_uri == 'pod:1' assert mock_client.product_uri == 'pod:1' opc_repository.set_security.assert_called_once() diff --git a/tests/laborious/worker/test_worker_main.py b/tests/laborious/worker/test_worker_main.py index 44ce6d4..92e872f 100644 --- a/tests/laborious/worker/test_worker_main.py +++ b/tests/laborious/worker/test_worker_main.py @@ -20,8 +20,9 @@ def test_main_exits_when_runtime_is_unset(mock_get_logger, mock_app_up, monkeypa logger = MagicMock() mock_get_logger.return_value = logger + coro = main() with raises(SystemExit) as exc: - asyncio.run(main()) + asyncio.run(coro) assert exc.value.code == 1 logger.custom_critical.assert_called_once() @@ -54,8 +55,9 @@ class TestMainHappyPath: mock_prepare_worker.return_value = worker mock_connect.return_value = MagicMock() + coro = main() with raises(SystemExit) as exc: - asyncio.run(main()) + asyncio.run(coro) return exc.value.code def test_runs_four_workers_without_the_import_flag( # noqa: PLR0913 @@ -195,8 +197,9 @@ class TestMainHappyPath: worker.run = AsyncMock(side_effect=RuntimeError('boom')) mock_prepare_worker.return_value = worker + coro = main() with raises(SystemExit) as exc: - asyncio.run(main()) + asyncio.run(coro) assert exc.value.code == 1 logger.custom_error.assert_called_once_with(ANY, ANY)