diff --git a/kpops/cli/main.py b/kpops/cli/main.py index 40e0ee4f0..54daa6561 100644 --- a/kpops/cli/main.py +++ b/kpops/cli/main.py @@ -251,6 +251,11 @@ def is_in_steps(component: PipelineComponent) -> bool: return component.name in component_names pipeline.filter(is_in_steps, filter_type) + + def get_step_names(steps_to_apply: list[PipelineComponent]) -> list[str]: + return [step.name for step in steps_to_apply] + + log.info(f"Filtered pipeline:\n{get_step_names(pipeline.components)}") if output: print_yaml(pipeline.to_yaml()) return pipeline diff --git a/kpops/pipeline.py b/kpops/pipeline.py index 08d241ae2..59f1c3a9b 100644 --- a/kpops/pipeline.py +++ b/kpops/pipeline.py @@ -80,11 +80,6 @@ def filter( case (FilterType.INCLUDE, False) | (FilterType.EXCLUDE, True): self.remove(component) - def get_step_names(steps_to_apply: list[PipelineComponent]) -> list[str]: - return [step.name for step in steps_to_apply] - - log.info(f"Filtered pipeline:\n{get_step_names(self.components)}") - def reverse(self) -> None: self.root.reverse() diff --git a/tests/pipeline/test_generate.py b/tests/pipeline/test_generate.py index 241c887c3..ce3ae7f45 100644 --- a/tests/pipeline/test_generate.py +++ b/tests/pipeline/test_generate.py @@ -1,7 +1,9 @@ from pathlib import Path +from unittest.mock import MagicMock import pytest import yaml +from pytest_mock import MockerFixture from snapshottest.module import SnapshotTest from typer.testing import CliRunner @@ -16,6 +18,10 @@ @pytest.mark.usefixtures("mock_env", "load_yaml_file_clear_cache") class TestGenerate: + @pytest.fixture(autouse=True) + def log_info(self, mocker: MockerFixture) -> MagicMock: + return mocker.patch("kpops.cli.main.log.info") + def test_python_api(self): pipeline = kpops.generate( RESOURCE_PATH / "first-pipeline" / "pipeline.yaml", @@ -29,7 +35,7 @@ def test_python_api(self): "filter", ] - def test_python_api_filter_include(self): + def test_python_api_filter_include(self, log_info: MagicMock): pipeline = kpops.generate( RESOURCE_PATH / "first-pipeline" / "pipeline.yaml", defaults=RESOURCE_PATH, @@ -39,8 +45,10 @@ def test_python_api_filter_include(self): ) assert len(pipeline) == 1 assert pipeline.root[0].type == "converter" + assert log_info.call_count == 1 + log_info.assert_any_call("Filtered pipeline:\n['converter']") - def test_python_api_filter_exclude(self): + def test_python_api_filter_exclude(self, log_info: MagicMock): pipeline = kpops.generate( RESOURCE_PATH / "first-pipeline" / "pipeline.yaml", defaults=RESOURCE_PATH, @@ -50,6 +58,10 @@ def test_python_api_filter_exclude(self): ) assert len(pipeline) == 1 assert pipeline.root[0].type == "filter" + assert log_info.call_count == 1 + log_info.assert_any_call( + "Filtered pipeline:\n['a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name']" + ) def test_load_pipeline(self, snapshot: SnapshotTest): result = runner.invoke( diff --git a/tests/pipeline/test_pipeline.py b/tests/pipeline/test_pipeline.py index 57fbb44d9..c027dd8f8 100644 --- a/tests/pipeline/test_pipeline.py +++ b/tests/pipeline/test_pipeline.py @@ -1,10 +1,8 @@ from collections.abc import Callable from dataclasses import dataclass from typing import cast -from unittest.mock import MagicMock import pytest -from pytest_mock import MockerFixture from kpops.cli.options import FilterType from kpops.components import PipelineComponent @@ -45,30 +43,21 @@ def pipeline(self) -> Pipeline: pipeline.add(cast(PipelineComponent, test_component_3)) return pipeline - @pytest.fixture(autouse=True) - def log_info(self, mocker: MockerFixture) -> MagicMock: - return mocker.patch("kpops.pipeline.log.info") - - def test_filter_include(self, log_info: MagicMock, pipeline: Pipeline): + def test_filter_include(self, pipeline: Pipeline): pipeline.filter(predicate({"example2", "example3"}), FilterType.INCLUDE) assert len(pipeline.components) == 2 assert test_component_2 in pipeline.components assert test_component_3 in pipeline.components - assert log_info.call_count == 1 - log_info.assert_any_call("Filtered pipeline:\n['example2', 'example3']") def test_filter_include_empty(self, pipeline: Pipeline): pipeline.filter(predicate(set()), FilterType.INCLUDE) assert len(pipeline.components) == 0 - def test_filter_exclude(self, log_info: MagicMock, pipeline: Pipeline): + def test_filter_exclude(self, pipeline: Pipeline): pipeline.filter(predicate({"example2", "example3"}), FilterType.EXCLUDE) assert len(pipeline.components) == 1 assert test_component_1 in pipeline.components - assert log_info.call_count == 1 - log_info.assert_any_call("Filtered pipeline:\n['example1']") - def test_filter_exclude_empty(self, pipeline: Pipeline): pipeline.filter(predicate(set()), FilterType.EXCLUDE) assert len(pipeline.components) == 3