SIENTIAPDE-1241: Fixed formatting and linted code
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -144,7 +144,9 @@ def test_start_prometheus_server_custom_port(mock_metrics, mock_start_http_serve
|
||||
@patch('model_manager.worker.worker.start_http_server')
|
||||
@patch('model_manager.worker.worker.metrics')
|
||||
@patch('model_manager.worker.worker.os._exit')
|
||||
def test_start_prometheus_server_failure(mock_exit, mock_metrics, mock_start_http_server, mock_env_vars):
|
||||
def test_start_prometheus_server_failure(
|
||||
mock_exit, mock_metrics, mock_start_http_server, mock_env_vars
|
||||
):
|
||||
"""Test Prometheus server startup failure."""
|
||||
from model_manager.worker.worker import start_prometheus_server
|
||||
|
||||
@@ -194,7 +196,10 @@ async def test_main_successful_startup(
|
||||
|
||||
# Setup mocks
|
||||
mock_get_logger.return_value = mock_logger
|
||||
mock_build_mongodb.return_value = {'connection_string': 'mongodb://test', 'database_name': 'test_db'}
|
||||
mock_build_mongodb.return_value = {
|
||||
'connection_string': 'mongodb://test',
|
||||
'database_name': 'test_db',
|
||||
}
|
||||
mock_build_postgres.return_value = {}
|
||||
mock_build_mlflow.return_value = {}
|
||||
mock_build_minio.return_value = {}
|
||||
@@ -209,7 +214,9 @@ async def test_main_successful_startup(
|
||||
mock_client_class.connect = AsyncMock(return_value=mock_client_instance)
|
||||
|
||||
mock_worker_instance = Mock()
|
||||
mock_worker_instance.run = AsyncMock(side_effect=asyncio.CancelledError()) # Simulate interruption
|
||||
mock_worker_instance.run = AsyncMock(
|
||||
side_effect=asyncio.CancelledError()
|
||||
) # Simulate interruption
|
||||
mock_worker_class.return_value = mock_worker_instance
|
||||
|
||||
mock_app_up = Mock()
|
||||
@@ -269,7 +276,10 @@ async def test_main_handles_exception(
|
||||
|
||||
# Setup mocks
|
||||
mock_get_logger.return_value = mock_logger
|
||||
mock_build_mongodb.return_value = {'connection_string': 'mongodb://test', 'database_name': 'test_db'}
|
||||
mock_build_mongodb.return_value = {
|
||||
'connection_string': 'mongodb://test',
|
||||
'database_name': 'test_db',
|
||||
}
|
||||
mock_build_postgres.return_value = {}
|
||||
mock_build_mlflow.return_value = {}
|
||||
mock_build_minio.return_value = {}
|
||||
@@ -342,10 +352,16 @@ async def test_main_temporal_client_configuration(
|
||||
"""Test that Temporal client is configured correctly."""
|
||||
from model_manager.worker.worker import main
|
||||
|
||||
with patch.dict(os.environ, {'TEMPORAL_HOST': 'temporal.example.com:7233', 'TEMPORAL_NAMESPACE': 'production'}):
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{'TEMPORAL_HOST': 'temporal.example.com:7233', 'TEMPORAL_NAMESPACE': 'production'},
|
||||
):
|
||||
# Setup mocks
|
||||
mock_get_logger.return_value = mock_logger
|
||||
mock_build_mongodb.return_value = {'connection_string': 'mongodb://test', 'database_name': 'test_db'}
|
||||
mock_build_mongodb.return_value = {
|
||||
'connection_string': 'mongodb://test',
|
||||
'database_name': 'test_db',
|
||||
}
|
||||
mock_build_postgres.return_value = {}
|
||||
mock_build_mlflow.return_value = {}
|
||||
mock_build_minio.return_value = {}
|
||||
@@ -415,7 +431,10 @@ async def test_main_worker_configuration(
|
||||
|
||||
# Setup mocks
|
||||
mock_get_logger.return_value = mock_logger
|
||||
mock_build_mongodb.return_value = {'connection_string': 'mongodb://test', 'database_name': 'test_db'}
|
||||
mock_build_mongodb.return_value = {
|
||||
'connection_string': 'mongodb://test',
|
||||
'database_name': 'test_db',
|
||||
}
|
||||
mock_build_postgres.return_value = {}
|
||||
mock_build_mlflow.return_value = {}
|
||||
mock_build_minio.return_value = {}
|
||||
@@ -472,8 +491,6 @@ def test_main_entrypoint(mock_asyncio_run):
|
||||
"""Test the __main__ entrypoint."""
|
||||
# Import and execute the main block
|
||||
with patch.object(sys, 'argv', ['worker.py']):
|
||||
import importlib
|
||||
|
||||
import model_manager.worker.worker as worker_module
|
||||
|
||||
# Simulate running the module
|
||||
@@ -495,7 +512,9 @@ def test_worker_module_docstring():
|
||||
|
||||
@patch('model_manager.worker.worker.start_http_server')
|
||||
@patch('model_manager.worker.worker.metrics')
|
||||
def test_start_prometheus_server_prints_success(mock_metrics, mock_start_http_server, capsys, mock_env_vars):
|
||||
def test_start_prometheus_server_prints_success(
|
||||
mock_metrics, mock_start_http_server, capsys, mock_env_vars
|
||||
):
|
||||
"""Test that start_prometheus_server prints success message."""
|
||||
from model_manager.worker.worker import start_prometheus_server
|
||||
|
||||
@@ -511,7 +530,9 @@ def test_start_prometheus_server_prints_success(mock_metrics, mock_start_http_se
|
||||
@patch('model_manager.worker.worker.start_http_server')
|
||||
@patch('model_manager.worker.worker.metrics')
|
||||
@patch('model_manager.worker.worker.os._exit')
|
||||
def test_start_prometheus_server_prints_failure(mock_exit, mock_metrics, mock_start_http_server, capsys, mock_env_vars):
|
||||
def test_start_prometheus_server_prints_failure(
|
||||
mock_exit, mock_metrics, mock_start_http_server, capsys, mock_env_vars
|
||||
):
|
||||
"""Test that start_prometheus_server prints failure message."""
|
||||
from model_manager.worker.worker import start_prometheus_server
|
||||
|
||||
@@ -522,5 +543,3 @@ def test_start_prometheus_server_prints_failure(mock_exit, mock_metrics, mock_st
|
||||
captured = capsys.readouterr()
|
||||
assert 'Failed to start Prometheus server' in captured.out
|
||||
assert 'Test error' in captured.out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user