Skip to content

Commit 1b3b388

Browse files
committed
feat: add logging test scripts to validate logging setup and functionality
1 parent 6310c90 commit 1b3b388

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

examples/simple_logging_test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
from pathlib import Path
3+
4+
# Add project root to path for local imports
5+
project_root = Path(__file__).parents[1]
6+
sys.path.insert(0, str(project_root))
7+
8+
# Import after path modification
9+
# pylint: disable=wrong-import-position
10+
from pdf2table import get_logger
11+
12+
def main():
13+
"""Main function to test logging."""
14+
logger = get_logger(__name__)
15+
16+
print("🧪 Simple Logging Test - Colored Headers")
17+
print("=" * 45)
18+
19+
logger.debug("🔍 This is a DEBUG message (cyan)")
20+
logger.info("ℹ️ This is an INFO message (green)")
21+
logger.warning("⚠️ This is a WARNING message (yellow)")
22+
logger.error("❌ This is an ERROR message (red)")
23+
24+
# Test without actual critical error
25+
logger.log(50, "🚨 This is a CRITICAL level message (magenta)")
26+
27+
print("\n✅ Color test completed!")
28+
print(f"Python version: {sys.version}")
29+
print(f"Script location: {__file__}")
30+
31+
logger.info("✨ Colored logging test completed successfully")
32+
33+
print("\n💡 To disable colors, set: PDF2TABLE_USE_COLORS=false")
34+
print("💡 To test without colors: PDF2TABLE_USE_COLORS=false uv run examples/simple_logging_test.py")
35+
36+
if __name__ == "__main__":
37+
main()

scripts/test_logging.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# Test script for validating the logging setup using uv run.
3+
# This script demonstrates the recommended way to run Python code in this project.
4+
5+
echo "Pdf2Table Logging Setup Test"
6+
echo "============================="
7+
8+
# Test basic logging import and functionality
9+
echo "1. Testing basic logging setup..."
10+
cat > /tmp/test_basic_logging.py << 'EOF'
11+
#!/usr/bin/env -S uv run --script
12+
# /// script
13+
# requires-python = ">=3.8"
14+
# dependencies = []
15+
# ///
16+
17+
import sys
18+
from pathlib import Path
19+
20+
# Add project root to path
21+
project_root = Path.cwd()
22+
sys.path.insert(0, str(project_root))
23+
24+
try:
25+
from pdf2table import get_logger, setup_logging
26+
logger = get_logger('test')
27+
logger.info('✓ Logging setup test successful')
28+
print('✓ Logging imports work correctly')
29+
print('✓ Logger created successfully')
30+
print('✓ Log message sent')
31+
except Exception as e:
32+
print(f'✗ Error: {e}')
33+
exit(1)
34+
EOF
35+
36+
uv run /tmp/test_basic_logging.py
37+
38+
if [ $? -eq 0 ]; then
39+
echo "✓ Basic logging test passed"
40+
else
41+
echo "✗ Basic logging test failed"
42+
exit 1
43+
fi
44+
45+
# Test with debug level
46+
echo ""
47+
echo "2. Testing debug level logging..."
48+
cat > /tmp/test_debug_logging.py << 'EOF'
49+
#!/usr/bin/env -S uv run --script
50+
# /// script
51+
# requires-python = ">=3.8"
52+
# dependencies = []
53+
# ///
54+
55+
import sys
56+
from pathlib import Path
57+
58+
project_root = Path.cwd()
59+
sys.path.insert(0, str(project_root))
60+
61+
from pdf2table import get_logger
62+
logger = get_logger('debug_test')
63+
logger.debug('This is a debug message')
64+
logger.info('This is an info message')
65+
logger.warning('This is a warning message')
66+
print('✓ Debug level logging test completed')
67+
EOF
68+
69+
PDF2TABLE_LOG_LEVEL=DEBUG uv run /tmp/test_debug_logging.py
70+
71+
# Test logging demo script
72+
echo ""
73+
echo "3. Testing simple logging test script..."
74+
if [ -f "examples/simple_logging_test.py" ]; then
75+
echo "Running simple logging test with uv run..."
76+
uv run examples/simple_logging_test.py > /dev/null 2>&1
77+
if [ $? -eq 0 ]; then
78+
echo "✓ Simple logging test script executed successfully"
79+
else
80+
echo "✗ Simple logging test script failed"
81+
exit 1
82+
fi
83+
else
84+
echo "✗ Simple logging test script not found"
85+
exit 1
86+
fi
87+
88+
# Check if log files were created
89+
echo ""
90+
echo "4. Checking log file creation..."
91+
if [ -d "logs" ]; then
92+
if [ -f "logs/pdf2table.log" ]; then
93+
echo "✓ Main log file created: logs/pdf2table.log"
94+
echo " Last few entries:"
95+
tail -3 logs/pdf2table.log | sed 's/^/ /'
96+
else
97+
echo "? Main log file not found (may not have been created yet)"
98+
fi
99+
100+
if [ -f "logs/pdf2table_errors.log" ]; then
101+
echo "✓ Error log file exists: logs/pdf2table_errors.log"
102+
else
103+
echo "? Error log file not found (normal if no errors occurred)"
104+
fi
105+
else
106+
echo "? Logs directory not found (may be created on first use)"
107+
fi
108+
109+
echo ""
110+
echo "============================="
111+
echo "Logging setup validation completed!"
112+
echo ""
113+
echo "Usage examples:"
114+
echo " uv run examples/simple_logging_test.py"
115+
echo " PDF2TABLE_LOG_LEVEL=DEBUG uv run examples/simple_logging_test.py"
116+
echo " uv run --python 3.11 examples/simple_logging_test.py"
117+
echo ""
118+
echo "Cleanup temporary files..."
119+
rm -f /tmp/test_basic_logging.py /tmp/test_debug_logging.py

0 commit comments

Comments
 (0)