Files
gogo2/test_safe_logging.py
Dobromir Popov df17a99247 wip
2025-07-23 13:39:41 +03:00

70 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Test script to verify safe_logging functionality
This script tests that the safe logging module properly handles:
1. Non-ASCII characters (emojis, smart quotes)
2. UTF-8 encoding
3. Error handling on Windows
"""
import logging
from safe_logging import setup_safe_logging
def test_safe_logging():
"""Test the safe logging module with various character types"""
# Setup safe logging
setup_safe_logging()
logger = logging.getLogger(__name__)
print("Testing Safe Logging Module...")
print("=" * 50)
# Test regular ASCII messages
logger.info("Regular ASCII message - this should work fine")
# Test messages with emojis
logger.info("Testing emojis: 🚀 💰 📈 📊 🔥")
# Test messages with smart quotes and special characters
logger.info("Testing smart quotes: Hello World Test")
# Test messages with various Unicode characters
logger.info("Testing Unicode: café résumé naïve Ω α β γ δ")
# Test messages with mixed content
logger.info("Mixed content: Regular text with emojis 🎉 and quotes like this")
# Test error messages with special characters
logger.error("Error with special chars: ❌ Failed to process €100.50")
# Test warning messages
logger.warning("Warning with symbols: ⚠️ Temperature is 37°C")
# Test debug messages
logger.debug("Debug info: Processing file data.txt at 95% completion ✓")
# Test exception handling with special characters
try:
raise ValueError("Error with emoji: 💥 Something went wrong!")
except Exception as e:
logger.exception("Exception caught with special chars: %s", str(e))
# Test formatting with special characters
symbol = "ETH/USDT"
price = 2500.50
change = 2.3
logger.info(f"Price update for {symbol}: ${price:.2f} (+{change}% 📈)")
# Test large message with many special characters
large_msg = "Large message: " + "🔄" * 50 + " Processing complete ✅"
logger.info(large_msg)
print("=" * 50)
print("✅ Safe logging test completed!")
print("If you see this message, all logging calls were successful.")
print("Check the log file at logs/safe_logging.log for the complete output.")
if __name__ == "__main__":
test_safe_logging()