-
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.
* fix: Add the image such that it can be read everywhere * fix: Differentiate between dev and user requirements * style: Pass to the flat pattern * feat: Add a new version number * test: Modify tests accordingly
- Loading branch information
1 parent
9e2b9eb
commit 4f3498f
Showing
12 changed files
with
34 additions
and
20 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
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
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 |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
__email__ = "[email protected]" | ||
__title__ = "Coloured Logger" | ||
__description__ = "A coloured logger for Python" | ||
__version__ = "1.0.2" | ||
__version__ = "1.0.3" | ||
__license__ = "MIT" | ||
|
||
# Path: src/coloured_logger/__init__.py | ||
from src.coloured_logger.logger import Logger | ||
# Path: coloured_logger/__init__.py | ||
from coloured_logger.logger import Logger | ||
|
||
__all__ = [ | ||
"logger_config", | ||
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 @@ | ||
pre-commit==3.0.4 | ||
black==22.10.0 | ||
pytest==7.2.1 | ||
pytest-cov==4.0.0 |
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 |
---|---|---|
@@ -1,4 +0,0 @@ | ||
pre-commit==3.0.4 | ||
black==22.10.0 | ||
pytest==7.2.1 | ||
pytest-cov==4.0.0 | ||
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
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 |
---|---|---|
@@ -1,38 +1,52 @@ | ||
"""Module to collect all tests for the logger module.""" | ||
|
||
import pytest | ||
from src.coloured_logger.logger import ColouredLogger, ColouredFormatter, formatter_message | ||
from coloured_logger.logger import ColouredLogger, ColouredFormatter, formatter_message | ||
import logging | ||
|
||
|
||
def test_formatter_message_with_color(): | ||
formatted_message = formatter_message("$BOLDHello$RESET", use_color=True) | ||
assert formatted_message == "\033[1mHello\033[0m" | ||
|
||
|
||
def test_formatter_message_without_color(): | ||
formatted_message = formatter_message("$BOLDHello$RESET", use_color=False) | ||
assert formatted_message == "Hello" | ||
|
||
|
||
def test_coloured_logger_creation(caplog): | ||
caplog.set_level(logging.INFO) | ||
logger = ColouredLogger("test_logger") | ||
|
||
# Ensure the logger has a stream handler | ||
assert any(isinstance(handler, logging.StreamHandler) for handler in logger.handlers) | ||
assert any( | ||
isinstance(handler, logging.StreamHandler) for handler in logger.handlers | ||
) | ||
|
||
# Ensure the formatter is a ColouredFormatter instance | ||
formatter = logger.handlers[0].formatter | ||
assert isinstance(formatter, ColouredFormatter) | ||
|
||
|
||
def test_coloured_formatter_format(): | ||
record = logging.LogRecord('test_logger', logging.INFO, '/path/to/source.py', 42, 'Test message', (), None, 'format') | ||
record = logging.LogRecord( | ||
"test_logger", | ||
logging.INFO, | ||
"/path/to/source.py", | ||
42, | ||
"Test message", | ||
(), | ||
None, | ||
"format", | ||
) | ||
formatter = ColouredFormatter(ColouredLogger.FORMAT, use_color=True) | ||
|
||
# Ensure the log message is formatted with colours | ||
formatted_message = formatter.format(record) | ||
|
||
expected_message = ( | ||
"\033[1m[test_logger ]\033[0m[\033[1;32mINFO \033[0m] Test message (\033[1m/path/to/source.py\033[0m:42)" | ||
) | ||
|
||
expected_message = "\033[1m[test_logger ]\033[0m[\033[1;32mINFO \033[0m] Test message (\033[1m/path/to/source.py\033[0m:42)" | ||
assert formatted_message[55:67] == expected_message[66:78] | ||
assert formatted_message.split("[")[3] == expected_message.split("[")[5].replace(" ", "") | ||
assert formatted_message.split("[")[3] == expected_message.split("[")[5].replace( | ||
" ", "" | ||
) |