fix: Update exception handling in GraphManager and improve logger initialization tests to avoid UnboundLocalError
This commit is contained in:
@@ -105,7 +105,9 @@ class TestInit:
|
||||
f"{temp_log_dir}/thechart.error.log",
|
||||
)
|
||||
|
||||
assert src.init.log_files == expected_files
|
||||
# Access the (re)loaded module directly from sys.modules to avoid
|
||||
# UnboundLocalError when the conditional local import path isn't taken.
|
||||
assert sys.modules['init'].log_files == expected_files
|
||||
|
||||
def test_testing_mode_detection(self, temp_log_dir):
|
||||
"""Test that testing mode is detected correctly."""
|
||||
@@ -118,12 +120,14 @@ class TestInit:
|
||||
else:
|
||||
import src.init
|
||||
|
||||
assert src.init.testing_mode is True
|
||||
# Access via sys.modules to avoid UnboundLocalError from conditional import
|
||||
assert sys.modules['init'].testing_mode is True
|
||||
|
||||
# Test with non-DEBUG level
|
||||
with patch('init.LOG_LEVEL', 'INFO'):
|
||||
importlib.reload(sys.modules['init'])
|
||||
assert src.init.testing_mode is False
|
||||
# Access via sys.modules to avoid UnboundLocalError from conditional import
|
||||
assert sys.modules['init'].testing_mode is False
|
||||
|
||||
def test_log_clear_true(self, temp_log_dir):
|
||||
"""Test log file clearing when LOG_CLEAR is True."""
|
||||
@@ -237,9 +241,10 @@ class TestInit:
|
||||
import src.init
|
||||
|
||||
# Check that expected objects are available
|
||||
assert hasattr(src.init, 'logger')
|
||||
assert hasattr(src.init, 'log_files')
|
||||
assert hasattr(src.init, 'testing_mode')
|
||||
mod = sys.modules['init']
|
||||
assert hasattr(mod, 'logger')
|
||||
assert hasattr(mod, 'log_files')
|
||||
assert hasattr(mod, 'testing_mode')
|
||||
|
||||
def test_log_path_printing(self, temp_log_dir):
|
||||
"""Test that LOG_PATH is printed when directory is created."""
|
||||
|
||||
Reference in New Issue
Block a user