SIENTIAPDE-1316
Update .gitignore and refactor metrics.py, activities.py, and gates.py for improved clarity and consistency. Added coverage.xml and cache directories to .gitignore. Standardized string formatting and parameter handling in metrics and activities classes, enhancing code readability. Removed the deprecated faker.py file and adjusted related tests accordingly.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from unittest.mock import AsyncMock, patch, ANY, call
|
||||
from unittest.mock import ANY, AsyncMock, call, patch
|
||||
|
||||
from pytest import fixture, mark
|
||||
from scouter.workflow.scouter import Scouter
|
||||
|
||||
from scouter.activities.activities import Activities
|
||||
from scouter.workflow.scouter import Scouter
|
||||
|
||||
|
||||
@fixture
|
||||
@@ -12,17 +14,16 @@ def scouter():
|
||||
@mark.asyncio
|
||||
@patch('scouter.workflow.scouter.workflow', new_callable=AsyncMock)
|
||||
async def test_scouter_workflow(mock_workflow, scouter):
|
||||
|
||||
mock_workflow.execute_local_activity_method.side_effect = [
|
||||
'test_last_data_timestamp',
|
||||
'test_data'
|
||||
'test_data',
|
||||
]
|
||||
await scouter.run(
|
||||
input_data={
|
||||
'topic': 'test_topic',
|
||||
'schedule_name': 'test_schedule',
|
||||
'model_name': 'test_model',
|
||||
'model_id': 'test_model_id'
|
||||
'model_id': 'test_model_id',
|
||||
}
|
||||
)
|
||||
|
||||
@@ -31,7 +32,7 @@ async def test_scouter_workflow(mock_workflow, scouter):
|
||||
'model_id': 'test_model_id',
|
||||
'model_name': 'test_model',
|
||||
'schedule_name': 'test_schedule',
|
||||
'workflow_name': 'scouter'
|
||||
'workflow_name': 'scouter',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,15 +40,12 @@ async def test_scouter_workflow(mock_workflow, scouter):
|
||||
[
|
||||
call(
|
||||
Activities.get_last_data_timestamp,
|
||||
{
|
||||
**expected_metadata,
|
||||
'workflow_name': 'scouter',
|
||||
'schedule_name': 'test_schedule'
|
||||
},
|
||||
{**expected_metadata, 'workflow_name': 'scouter', 'schedule_name': 'test_schedule'},
|
||||
retry_policy=ANY,
|
||||
start_to_close_timeout=ANY
|
||||
start_to_close_timeout=ANY,
|
||||
)
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
mock_workflow.execute_local_activity_method.assert_has_calls(
|
||||
[
|
||||
@@ -55,13 +53,14 @@ async def test_scouter_workflow(mock_workflow, scouter):
|
||||
Activities.load_latest_data,
|
||||
{
|
||||
**expected_metadata,
|
||||
'collection_name': "raw_test_schedule",
|
||||
'last_data_timestamp': 'test_last_data_timestamp'
|
||||
'collection_name': 'raw_test_schedule',
|
||||
'last_data_timestamp': 'test_last_data_timestamp',
|
||||
},
|
||||
retry_policy=ANY,
|
||||
start_to_close_timeout=ANY
|
||||
start_to_close_timeout=ANY,
|
||||
)
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
mock_workflow.execute_activity_method.assert_called_once_with(
|
||||
Activities.put_last_data_timestamp,
|
||||
@@ -69,10 +68,10 @@ async def test_scouter_workflow(mock_workflow, scouter):
|
||||
**expected_metadata,
|
||||
'data': 'test_data',
|
||||
'workflow_name': 'scouter',
|
||||
'schedule_name': 'test_schedule'
|
||||
'schedule_name': 'test_schedule',
|
||||
},
|
||||
retry_policy=ANY,
|
||||
start_to_close_timeout=ANY
|
||||
start_to_close_timeout=ANY,
|
||||
)
|
||||
|
||||
mock_workflow.execute_child_workflow.assert_called_once_with(
|
||||
@@ -84,24 +83,21 @@ async def test_scouter_workflow(mock_workflow, scouter):
|
||||
'workflow_name': 'scouter',
|
||||
'schedule_name': 'test_schedule',
|
||||
'model_name': 'test_model',
|
||||
'model_id': 'test_model_id'
|
||||
}
|
||||
'model_id': 'test_model_id',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@patch('scouter.workflow.scouter.workflow', new_callable=AsyncMock)
|
||||
async def test_scouter_workflow_empty(mock_workflow, scouter):
|
||||
mock_workflow.execute_local_activity_method.side_effect = [
|
||||
'test_last_data_timestamp',
|
||||
{}
|
||||
]
|
||||
mock_workflow.execute_local_activity_method.side_effect = ['test_last_data_timestamp', {}]
|
||||
await scouter.run(
|
||||
input_data={
|
||||
'topic': 'test_topic',
|
||||
'schedule_name': 'test_schedule',
|
||||
'model_name': 'test_model',
|
||||
'model_id': 'test_model_id'
|
||||
'model_id': 'test_model_id',
|
||||
}
|
||||
)
|
||||
|
||||
@@ -110,7 +106,7 @@ async def test_scouter_workflow_empty(mock_workflow, scouter):
|
||||
'model_id': 'test_model_id',
|
||||
'model_name': 'test_model',
|
||||
'schedule_name': 'test_schedule',
|
||||
'workflow_name': 'scouter'
|
||||
'workflow_name': 'scouter',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,13 +116,14 @@ async def test_scouter_workflow_empty(mock_workflow, scouter):
|
||||
Activities.load_latest_data,
|
||||
{
|
||||
**expected_metadata,
|
||||
'collection_name': "raw_test_schedule",
|
||||
'last_data_timestamp': 'test_last_data_timestamp'
|
||||
'collection_name': 'raw_test_schedule',
|
||||
'last_data_timestamp': 'test_last_data_timestamp',
|
||||
},
|
||||
retry_policy=ANY,
|
||||
start_to_close_timeout=ANY
|
||||
start_to_close_timeout=ANY,
|
||||
)
|
||||
])
|
||||
]
|
||||
)
|
||||
|
||||
mock_workflow.execute_activity_method.assert_not_called()
|
||||
mock_workflow.execute_child_workflow.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user