-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unicode_logging.py
More file actions
57 lines (46 loc) · 1.85 KB
/
test_unicode_logging.py
File metadata and controls
57 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""
Quick test to check if Unicode encoding errors are resolved in logging
"""
import logging
import sys
import os
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_unicode_logging():
"""Test if logging with different encodings works"""
# Configure logger similar to the project
logger = logging.getLogger("test")
logger.setLevel(logging.INFO)
# Create console handler
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
# Create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
print("Testing Unicode logging safety...")
# Test ASCII-safe messages (should work)
try:
logger.info("[BRAIN] Initializing system...")
logger.info("[OK] System ready")
logger.info("[INFO] Processing query")
logger.warning("[WARN] This is a warning")
logger.error("[ERROR] This is an error")
print("✅ ASCII-safe logging: PASSED")
except Exception as e:
print(f"❌ ASCII-safe logging: FAILED - {e}")
# Test emoji messages (should fail on Windows cp1252)
try:
logger.info("🧠 Initializing system...")
logger.info("✅ System ready")
logger.info("🔍 Processing query")
logger.warning("⚠️ This is a warning")
logger.error("❌ This is an error")
print("✅ Emoji logging: PASSED (Unicode support available)")
except UnicodeEncodeError as e:
print(f"❌ Emoji logging: FAILED (expected on Windows) - {e}")
except Exception as e:
print(f"❌ Emoji logging: FAILED (unexpected error) - {e}")
if __name__ == "__main__":
test_unicode_logging()