feat: Improve environment variable handling and logging initialization, add fallback for canvas creation in GraphManager, and enhance SearchFilterWidget with debouncing and trace suppression
This commit is contained in:
@@ -8,98 +8,71 @@ import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
|
||||
|
||||
def _fresh_constants():
|
||||
"""Import or reload the constants module and return it.
|
||||
|
||||
Ensures a local binding exists in callers to avoid UnboundLocalError
|
||||
from conditional imports in the tests.
|
||||
"""
|
||||
import importlib
|
||||
# If already imported, reload to pick up env changes
|
||||
if 'constants' in sys.modules:
|
||||
import constants # bind locally for importlib.reload
|
||||
return importlib.reload(constants)
|
||||
# Otherwise, import fresh
|
||||
import constants
|
||||
return constants
|
||||
|
||||
|
||||
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'])
|
||||
import constants
|
||||
else:
|
||||
import constants
|
||||
|
||||
constants = _fresh_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'])
|
||||
import constants
|
||||
else:
|
||||
import constants
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_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
|
||||
|
||||
constants = _fresh_constants()
|
||||
assert constants.LOG_LEVEL == "WARNING"
|
||||
|
||||
def test_dotenv_override(self):
|
||||
|
||||
Reference in New Issue
Block a user