diff --git a/kpops/cli/registry.py b/kpops/cli/registry.py index 30a9c1205..8b6c99522 100644 --- a/kpops/cli/registry.py +++ b/kpops/cli/registry.py @@ -3,6 +3,7 @@ import importlib import inspect import os +from pathlib import Path import sys from collections.abc import Iterator from dataclasses import dataclass, field @@ -17,7 +18,7 @@ T = TypeVar("T") ClassDict = dict[str, type[T]] # type -> class -sys.path.append(os.getcwd()) +sys.path.append(str(Path.cwd())) @dataclass diff --git a/kpops/utils/yaml_loading.py b/kpops/utils/yaml_loading.py index d8aee8b95..36848d4d2 100644 --- a/kpops/utils/yaml_loading.py +++ b/kpops/utils/yaml_loading.py @@ -20,7 +20,7 @@ def generate_hashkey( def load_yaml_file( file_path: Path, *, substitution: Mapping[str, Any] | None = None, ) -> dict | list[dict]: - with open(file_path) as yaml_file: + with file_path.open() as yaml_file: return yaml.load(substitute(yaml_file.read(), substitution), Loader=yaml.Loader) diff --git a/tests/component_handlers/kafka_connect/test_connect_wrapper.py b/tests/component_handlers/kafka_connect/test_connect_wrapper.py index 714b263d5..afac5538d 100644 --- a/tests/component_handlers/kafka_connect/test_connect_wrapper.py +++ b/tests/component_handlers/kafka_connect/test_connect_wrapper.py @@ -495,9 +495,9 @@ def test_should_create_correct_validate_connector_config_and_name_gets_added( ) def test_should_parse_validate_connector_config(self, httpx_mock: HTTPXMock): - with open( + with Path( DEFAULTS_PATH / "connect_validation_response.json", - ) as f: + ).open() as f: actual_response = json.load(f) httpx_mock.add_response( method="PUT", diff --git a/tests/component_handlers/topic/test_proxy_wrapper.py b/tests/component_handlers/topic/test_proxy_wrapper.py index f7142f496..73e8aab4d 100644 --- a/tests/component_handlers/topic/test_proxy_wrapper.py +++ b/tests/component_handlers/topic/test_proxy_wrapper.py @@ -36,9 +36,9 @@ def _setup(self, httpx_mock: HTTPXMock): ) self.proxy_wrapper = ProxyWrapper(pipeline_config=config) - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses" / "cluster-info.json", - ) as f: + ).open() as f: cluster_response = json.load(f) httpx_mock.add_response( diff --git a/tests/component_handlers/topic/test_topic_handler.py b/tests/component_handlers/topic/test_topic_handler.py index 9678cd86f..6ca8410e2 100644 --- a/tests/component_handlers/topic/test_topic_handler.py +++ b/tests/component_handlers/topic/test_topic_handler.py @@ -51,19 +51,19 @@ def log_error_mock(self, mocker: MockerFixture) -> MagicMock: @pytest.fixture(autouse=True) def get_topic_response_mock(self) -> MagicMock: - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses/get_topic_response.json", - ) as f: + ).open() as f: response = json.load(f) - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses/broker_response.json", - ) as f: + ).open() as f: broker_response = json.load(f) - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses/topic_config_response.json", - ) as f: + ).open() as f: response_topic_config = json.load(f) wrapper = MagicMock() @@ -76,14 +76,14 @@ def get_topic_response_mock(self) -> MagicMock: @pytest.fixture(autouse=True) def get_default_topic_response_mock(self) -> MagicMock: - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses/get_default_topic_response.json", - ) as f: + ).open() as f: response = json.load(f) - with open( + with Path( DEFAULTS_PATH / "kafka_rest_proxy_responses/broker_response.json", - ) as f: + ).open() as f: broker_response = json.load(f) wrapper = MagicMock()