Skip to content

Commit a40e3e4

Browse files
kmeinerzkmeinerz1
andauthored
Fix failing github checks (#814)
* changed printing error to stderr in `run_logprep` to using the logger.error --------- Co-authored-by: kmeinerz1 <kaithomas.meinerz@bwi.de>
1 parent 368df94 commit a40e3e4

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- prevent the auto rule tester from loading rules directly defined inside the config, since they break the auto rule tester and can't have tests anyways
1818
- Fixed typo and broken link in documentation
1919
- Fixed assign_callback error in confluentkafka input
20+
- Fixed error logging in ` _get_configuration`, which caused the github checks to fail
2021

2122
## 16.1.0
2223
### Deprecations

logprep/run_logprep.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ def _print_version(config: "Configuration") -> None:
3434

3535

3636
def _get_configuration(config_paths: tuple[str]) -> Configuration:
37+
38+
console_logger = logging.getLogger("console")
3739
try:
3840
config = Configuration.from_sources(config_paths)
3941
config.logger.setup_logging()
4042
logger = logging.getLogger("root") # pylint: disable=redefined-outer-name
41-
42-
console_logger = logging.getLogger("console")
4343
console_handler = console_logger.handlers[0]
4444
listener = LogprepMPQueueListener(logqueue, console_handler)
4545
listener.start()
46-
47-
logger.info(f"Log level set to '{logging.getLevelName(logger.level)}'")
46+
logger.info("Log level set to '%s'", logging.getLevelName(logger.level))
4847
listener.stop()
4948
return config
5049
except InvalidConfigurationError as error:
51-
print(f"InvalidConfigurationError: {error}", file=sys.stderr)
50+
console_logger.error("InvalidConfigurationError: %s", error)
5251
sys.exit(EXITCODES.CONFIGURATION_ERROR)
5352

5453

tests/unit/test_run_logprep.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ def test_cli_commands_with_configs(self, command: str, target: str):
7979
("test", "dry-run", "input_data"),
8080
],
8181
)
82-
def test_cli_invokes_default_config_location(self, command):
82+
def test_cli_invokes_default_config_location(self, command, caplog):
8383
result = self.cli_runner.invoke(cli, [*command])
8484
assert result.exit_code != 0
85-
assert "does not exist: /etc/logprep/pipeline.yml" in result.stdout
85+
assert "does not exist: /etc/logprep/pipeline.yml" in caplog.text
8686

8787
@mock.patch("logprep.run_logprep.Runner")
8888
def test_cli_run_starts_runner_with_config(self, mock_runner):
@@ -108,11 +108,11 @@ def test_cli_run_starts_runner_with_multiple_configs(self, mock_runner):
108108
mock_runner.get_runner.assert_called_with(expected_config)
109109
runner_instance.start.assert_called()
110110

111-
def test_exits_after_getter_error_for_not_existing_protocol(self):
111+
def test_exits_after_getter_error_for_not_existing_protocol(self, caplog):
112112
args = ["run", "almighty_protocol://tests/testdata/config/config.yml"]
113113
result = self.cli_runner.invoke(cli, args)
114114
assert result.exit_code == EXITCODES.CONFIGURATION_ERROR.value
115-
assert "No getter for protocol 'almighty_protocol'" in result.output
115+
assert "No getter for protocol 'almighty_protocol'" in caplog.text
116116

117117
@mock.patch("logprep.util.configuration.Configuration._verify")
118118
def test_test_config_verifies_configuration_successfully(self, mock_verify):
@@ -215,15 +215,15 @@ def test_run_version_arg_prints_with_http_config_without_exposing_secret_data(se
215215
assert "username" not in result.output
216216
assert "password" not in result.output
217217

218-
def test_run_no_config_error_is_printed_if_given_config_file_does_not_exist(self):
218+
def test_run_no_config_error_is_printed_if_given_config_file_does_not_exist(self, caplog):
219219
non_existing_config_file = "/tmp/does/not/exist.yml"
220220
result = self.cli_runner.invoke(cli, ["run", non_existing_config_file])
221221
assert result.exit_code == EXITCODES.CONFIGURATION_ERROR.value
222222
expected_lines = (
223223
f"One or more of the given config file(s) does not exist: "
224224
f"{non_existing_config_file}\n"
225225
)
226-
assert expected_lines in result.output
226+
assert expected_lines in caplog.text
227227

228228
@mock.patch("logprep.runner.Runner._runner")
229229
def test_main_calls_runner_stop_on_any_exception(self, mock_runner):
@@ -280,7 +280,7 @@ def test_run_logprep_logs_log_level(self, mock_info):
280280
with mock.patch("logprep.run_logprep.Runner"):
281281
with pytest.raises(SystemExit):
282282
run_logprep.run(("tests/testdata/config/config.yml",))
283-
mock_info.assert_has_calls([mock.call("Log level set to 'INFO'")])
283+
mock_info.assert_has_calls([mock.call("Log level set to '%s'", "INFO")])
284284

285285
@mock.patch("logprep.generator.kafka.run_load_tester.LoadTester.run")
286286
def test_generate_kafka_starts_kafka_load_tester(self, mock_kafka_load_tester):

0 commit comments

Comments
 (0)