Skip to content

Commit

Permalink
- Add tests for log.py
Browse files Browse the repository at this point in the history
- Modify log levels to be lower case
  • Loading branch information
AustinCullar committed Sep 26, 2024
1 parent effe388 commit 26c2062
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ def __init__(self, log_level_str: str):
self.logger = self.initialize_logging()

def get_log_level(self, log_level: str) -> int:
log_level = log_level.upper()

if log_level == "DEBUG":
if log_level == "debug":
log_level = logging.DEBUG
elif log_level == "INFO":
elif log_level == "info":
log_level = logging.INFO
elif log_level == "WARNING":
elif log_level == "warn":
log_level = logging.WARNING
else:
elif log_level == 'error':
log_level = logging.ERROR
else:
raise ValueError("Invalid logger level specified: {}".format(log_level))

return log_level

Expand Down
32 changes: 32 additions & 0 deletions src/tests/test_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Tests for the Logging class.
"""
import pytest

# Astro modules
from src.log import Logger


class TestLogging:
@pytest.mark.parametrize('level', ['debug', 'info', 'warn', 'error', 'asdf'])
def test_get_log_level(self, level):
valid_levels = ['debug', 'info', 'warn', 'error']

if level in valid_levels:
logger = Logger(level)
log_level = logger.get_log_level(level)

if level == 'debug':
assert log_level == 10
elif level == 'info':
assert log_level == 20
elif level == 'warn':
assert log_level == 30
elif level == 'error':
assert log_level == 40

else: # should assert error if invalid log level specified
with pytest.raises(ValueError) as exception:
logger = Logger(level) # this will call get_log_level()

assert str(exception.value) == "Invalid logger level specified: {}".format(level)

0 comments on commit 26c2062

Please sign in to comment.