This commit includes several changes: - Reorganized imports and class inheritance in activities.py, gates.py and mlflow.py for better readability and maintainability. - Improved error handling and logging in gates.py and mlflow.py. - Added input validation and filtering in gates.py to ensure data quality. - Enhanced prediction formatting and storage policy management in gates.py. - Updated metrics.py to use consistent naming conventions and labels. - Refactored connectors_config.py to use type hints and improve code clarity. - Updated conditional and MLFlow filters for better data quality checks. - Improved model repository logic for retraining and updating models. - Enhanced worker.py to include SDK metrics and improved error handling. - Refactored workflows for better modularity and error handling. - Updated tests to reflect the changes and improve test coverage.
98 lines
3.1 KiB
Python
98 lines
3.1 KiB
Python
from unittest.mock import ANY, MagicMock, patch
|
|
|
|
from pytest import mark
|
|
from sientia_do.temporal.activities.postgres import Postgres
|
|
|
|
from model_manager.activities.activities import Activities
|
|
from model_manager.activities.gates import Gates
|
|
from model_manager.activities.mlflow import MLFlow
|
|
|
|
|
|
@patch('model_manager.activities.activities.Postgres.__init__')
|
|
@patch('model_manager.activities.activities.MLFlow.__init__')
|
|
@patch('model_manager.activities.activities.Gates.__init__')
|
|
def test___init__(mock_gates_init, mock_mlflow_init, mock_postgres_init):
|
|
postgres_config = {
|
|
'host': 'localhost',
|
|
'port': 5432,
|
|
'user': 'postgres',
|
|
'password': 'postgres',
|
|
'dbname': 'postgres',
|
|
'min_connections': 1,
|
|
'max_connections': 10,
|
|
}
|
|
|
|
mlflow_config = {'host': 'localhost', 'port': 5000, 'username': 'mlflow', 'password': 'mlflow'}
|
|
|
|
logger = MagicMock()
|
|
notification_handler = MagicMock()
|
|
|
|
activities = Activities(
|
|
postgres_config=postgres_config,
|
|
mlflow_config=mlflow_config,
|
|
logger=logger,
|
|
notification_handler=notification_handler,
|
|
)
|
|
|
|
assert isinstance(activities, Activities)
|
|
assert isinstance(activities, Postgres)
|
|
assert isinstance(activities, MLFlow)
|
|
assert isinstance(activities, Gates)
|
|
|
|
mock_postgres_init.assert_called_once_with(
|
|
ANY,
|
|
host=postgres_config['host'],
|
|
port=postgres_config['port'],
|
|
user=postgres_config['user'],
|
|
password=postgres_config['password'],
|
|
dbname=postgres_config['dbname'],
|
|
min_connections=postgres_config['min_connections'],
|
|
max_connections=postgres_config['max_connections'],
|
|
logger=logger,
|
|
notification_handler=notification_handler,
|
|
)
|
|
|
|
mock_mlflow_init.assert_called_once_with(
|
|
ANY,
|
|
mlflow_host=mlflow_config['host'],
|
|
mlflow_port=mlflow_config['port'],
|
|
mlflow_username=mlflow_config['username'],
|
|
mlflow_password=mlflow_config['password'],
|
|
logger=logger,
|
|
notification_handler=notification_handler,
|
|
)
|
|
|
|
mock_gates_init.assert_called_once_with(
|
|
ANY, logger=logger, notification_handler=notification_handler
|
|
)
|
|
|
|
|
|
@mark.asyncio
|
|
@patch('model_manager.activities.activities.Postgres', return_value=MagicMock())
|
|
@patch('model_manager.activities.activities.MLFlow', return_value=MagicMock())
|
|
async def test_shutdown(_mock_mlflow_init, mock_postgres_init):
|
|
postgres_config = {
|
|
'host': 'localhost',
|
|
'port': 5432,
|
|
'user': 'postgres',
|
|
'password': 'postgres',
|
|
'dbname': 'postgres',
|
|
'min_connections': 1,
|
|
'max_connections': 10,
|
|
}
|
|
|
|
mlflow_config = {'host': 'localhost', 'port': 5000, 'username': 'mlflow', 'password': 'mlflow'}
|
|
|
|
logger = MagicMock()
|
|
notification_handler = MagicMock()
|
|
|
|
activities = Activities(
|
|
postgres_config=postgres_config,
|
|
mlflow_config=mlflow_config,
|
|
logger=logger,
|
|
notification_handler=notification_handler,
|
|
)
|
|
|
|
await activities.shutdown()
|
|
mock_postgres_init.close.assert_called_once()
|