- Added coverage version 7.10.1 with multiple wheel distributions. - Added iniconfig version 2.1.0 with its wheel distribution. - Added pluggy version 1.6.0 with its wheel distribution. - Added pygments version 2.19.2 with its wheel distribution. - Added pytest version 8.4.1 with its wheel distribution and dependencies. - Added pytest-cov version 6.2.1 with its wheel distribution and dependencies. - Added pytest-mock version 3.14.1 with its wheel distribution and dependencies. - Updated dev-dependencies to include coverage, pytest, pytest-cov, and pytest-mock. - Updated requires-dist to specify minimum versions for coverage, pytest, pytest-cov, and pytest-mock.
131 lines
4.4 KiB
Python
131 lines
4.4 KiB
Python
"""
|
|
Tests for constants module.
|
|
"""
|
|
import os
|
|
import pytest
|
|
from unittest.mock import patch
|
|
|
|
import sys
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
|
|
|
|
|
class TestConstants:
|
|
"""Test cases for the constants module."""
|
|
|
|
def test_default_log_level(self):
|
|
"""Test default LOG_LEVEL when not set in environment."""
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
# Re-import to get fresh values
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_LEVEL == "INFO"
|
|
|
|
def test_custom_log_level(self):
|
|
"""Test custom LOG_LEVEL from environment."""
|
|
with patch.dict(os.environ, {'LOG_LEVEL': 'debug'}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_LEVEL == "DEBUG"
|
|
|
|
def test_default_log_path(self):
|
|
"""Test default LOG_PATH when not set in environment."""
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_PATH == "/tmp/logs/thechart"
|
|
|
|
def test_custom_log_path(self):
|
|
"""Test custom LOG_PATH from environment."""
|
|
with patch.dict(os.environ, {'LOG_PATH': '/custom/log/path'}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_PATH == "/custom/log/path"
|
|
|
|
def test_default_log_clear(self):
|
|
"""Test default LOG_CLEAR when not set in environment."""
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_CLEAR == "False"
|
|
|
|
def test_custom_log_clear_true(self):
|
|
"""Test LOG_CLEAR when set to true in environment."""
|
|
with patch.dict(os.environ, {'LOG_CLEAR': 'true'}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_CLEAR == "True"
|
|
|
|
def test_custom_log_clear_false(self):
|
|
"""Test LOG_CLEAR when set to false in environment."""
|
|
with patch.dict(os.environ, {'LOG_CLEAR': 'false'}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_CLEAR == "False"
|
|
|
|
def test_log_level_case_insensitive(self):
|
|
"""Test that LOG_LEVEL is converted to uppercase."""
|
|
with patch.dict(os.environ, {'LOG_LEVEL': 'warning'}, clear=True):
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
assert constants.LOG_LEVEL == "WARNING"
|
|
|
|
def test_dotenv_override(self):
|
|
"""Test that dotenv override parameter is set to True."""
|
|
# This is a structural test since dotenv is loaded during import
|
|
with patch('constants.load_dotenv') as mock_load_dotenv:
|
|
import importlib
|
|
if 'constants' in sys.modules:
|
|
importlib.reload(sys.modules['constants'])
|
|
else:
|
|
import constants
|
|
|
|
mock_load_dotenv.assert_called_once_with(override=True)
|
|
|
|
def test_all_constants_are_strings(self):
|
|
"""Test that all constants are string type."""
|
|
import constants
|
|
|
|
assert isinstance(constants.LOG_LEVEL, str)
|
|
assert isinstance(constants.LOG_PATH, str)
|
|
assert isinstance(constants.LOG_CLEAR, str)
|
|
|
|
def test_constants_not_empty(self):
|
|
"""Test that constants are not empty strings."""
|
|
import constants
|
|
|
|
assert constants.LOG_LEVEL != ""
|
|
assert constants.LOG_PATH != ""
|
|
assert constants.LOG_CLEAR != ""
|