def test_utils():
"""Test utility functions"""
# Test logger setup
test_logger = setup_logger("test")
assert test_logger.level == logging.INFO
assert len(test_logger.handlers) == 1
# Test context loading/saving
test_path = Path("test_context.json")
test_data = {
"current_rotation": {"specialty": "ED"},
"learning_objectives": [],
"knowledge_profile": {"gaps": {}, "strengths": []}
}
# Test save
save_context_safely(test_data, test_path)
assert test_path.exists()
# Test load
loaded = load_context_safely(test_path)
assert loaded == test_data
# Cleanup
test_path.unlink()
print("Utility tests passed!")
# Run tests
if __name__ == "__main__":
test_utils()Utils
Shared utilities for the entire learning system
Setup
Utilities
setup_logger
setup_logger (name:str)
Set up module logger with consistent formatting
load_context_safely
load_context_safely (path:pathlib.Path)
*Safely load learning context from JSON file.
Args: path: Path to context file
Returns: dict: Loaded context data
Raises: ValueError: If file is invalid or inaccessible*
save_context_safely
save_context_safely (context:Dict, path:pathlib.Path)
*Safely save learning context to JSON file.
Args: context: Context data to save path: Path to save file
Raises: ValueError: If save operation fails*