Skip to content

Commit

Permalink
New release (#1)
Browse files Browse the repository at this point in the history
* 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
oscar-defelice authored Nov 23, 2023
1 parent 9e2b9eb commit 4f3498f
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/execute-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install -r requirements.txt
- name: Run pytest
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- markdownlint-disable MD033 -->
<div align="center">
<img src="images/logo.png" width="800px">
<img src="https://raw.githubusercontent.com/oscar-defelice/coloured-logger/develop/images/logo.png" width="800px">
</div>
<!-- markdownlint-enable MD033 -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import logging

from src.coloured_logger.logger_config import COLOURS, RESET_SEQ, COLOR_SEQ, BOLD_SEQ
from coloured_logger.logger_config import COLOURS, RESET_SEQ, COLOR_SEQ, BOLD_SEQ


def formatter_message(message, use_color=True):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions requirements-dev.txt
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
4 changes: 0 additions & 4 deletions requirements.txt
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
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
""" Setup file for the package."""
#!/usr/bin/env python3
import os
from src import coloured_logger
from src.coloured_logger import (
from coloured_logger import (
__version__,
__description__,
__author__,
Expand Down Expand Up @@ -33,7 +32,7 @@ def read(fname):
long_description_content_type="text/markdown",
keywords="security,scanner",
url="https://github.com/oscar-defelice/%s" % pypi_name,
packages=find_packages(where="src"),
packages=find_packages(),
package_dir={"": "src"},
include_package_data=True,
install_requires=requirements,
Expand Down
Empty file.
30 changes: 22 additions & 8 deletions tests/test_coloured_logger.py
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(
" ", ""
)

0 comments on commit 4f3498f

Please sign in to comment.