Skip to content

Commit

Permalink
Added _match_pattern patching
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Khaustova <ymax70rus@gmail.com>
  • Loading branch information
ElenaKhaustova committed Aug 27, 2024
1 parent 0ba5eed commit 2173f2a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/framework/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ def test_run(

@pytest.mark.usefixtures("mock_settings_context_class")
@pytest.mark.parametrize("fake_pipeline_name", [None, _FAKE_PIPELINE_NAME])
@pytest.mark.parametrize("match_pattern", [True, False])
def test_run_thread_runner(
self,
fake_project,
Expand All @@ -713,26 +714,30 @@ def test_run_thread_runner(
mock_context_class,
mock_thread_runner,
mocker,
match_pattern,
):
"""Test running the project via the session"""

mock_hook = mocker.patch(
"kedro.framework.session.session._create_hook_manager"
).return_value.hook

mock_pipelines = mocker.patch(
"kedro.framework.session.session.pipelines",
return_value={
_FAKE_PIPELINE_NAME: mocker.Mock(),
"__default__": mocker.Mock(),
},
)
mock_context = mock_context_class.return_value
mock_catalog = mock_context._get_catalog.return_value
mock_pipeline = mock_pipelines.__getitem__.return_value.filter.return_value
mocker.patch(
"kedro.io.data_catalog.DataCatalog._match_pattern",
return_value=match_pattern,
)

with KedroSession.create(fake_project) as session:
session.run(runner=mock_thread_runner, pipeline_name=fake_pipeline_name)

mock_context = mock_context_class.return_value
record_data = {
"session_id": fake_session_id,
"project_path": fake_project.as_posix(),
Expand All @@ -750,6 +755,8 @@ def test_run_thread_runner(
"namespace": None,
"runner": mock_thread_runner.__name__,
}
mock_catalog = mock_context._get_catalog.return_value
mock_pipeline = mock_pipelines.__getitem__.return_value.filter.return_value

mock_hook.before_pipeline_run.assert_called_once_with(
run_params=record_data, pipeline=mock_pipeline, catalog=mock_catalog
Expand Down

0 comments on commit 2173f2a

Please sign in to comment.