-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1c0027
commit cbe6faf
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# Copyright 2024 ABSA Group Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import pytest | ||
|
||
@pytest.fixture | ||
def mock_logging_setup(mocker): | ||
"""Fixture to mock the basic logging setup using pytest-mock.""" | ||
mock_log_config = mocker.patch("logging.basicConfig") | ||
yield mock_log_config | ||
|
||
@pytest.fixture() | ||
def mock_exit(code) -> list: | ||
exit_calls = [] | ||
exit_calls.append(code) | ||
return exit_calls |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# Copyright 2024 ABSA Group Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import logging | ||
import os | ||
import sys | ||
|
||
from logging import StreamHandler | ||
|
||
from release_notes_presence_check.utils.logging_config import setup_logging | ||
|
||
|
||
def validate_logging_config(mock_logging_setup, caplog, expected_level, expected_message): | ||
mock_logging_setup.assert_called_once() | ||
|
||
# Get the actual call arguments from the mock | ||
call_args = mock_logging_setup.call_args[1] # Extract the kwargs from the call | ||
|
||
# Validate the logging level and format | ||
assert call_args["level"] == expected_level | ||
assert call_args["format"] == "%(asctime)s - %(levelname)s - %(message)s" | ||
assert call_args["datefmt"] == "%Y-%m-%d %H:%M:%S" | ||
|
||
# Check that the handler is a StreamHandler and outputs to sys.stdout | ||
handlers = call_args["handlers"] | ||
assert 1 == len(handlers) # Only one handler is expected | ||
assert isinstance(handlers[0], StreamHandler) # Handler should be StreamHandler | ||
assert handlers[0].stream is sys.stdout # Stream should be sys.stdout | ||
|
||
# Check that the log message is present | ||
assert expected_message in caplog.text | ||
|
||
|
||
# setup_logging | ||
|
||
def test_setup_logging_default_logging_level(mock_logging_setup, caplog): | ||
with caplog.at_level(logging.INFO): | ||
setup_logging() | ||
|
||
validate_logging_config(mock_logging_setup, caplog, logging.INFO, "Logging configuration set up.") | ||
|
||
|
||
def test_setup_logging_debug_mode_enabled_by_ci(mock_logging_setup, caplog): | ||
os.environ["RUNNER_DEBUG"] = "1" | ||
|
||
with caplog.at_level(logging.DEBUG): | ||
setup_logging() | ||
|
||
validate_logging_config(mock_logging_setup, caplog, logging.DEBUG, "Debug mode enabled by CI runner.") |