|
| 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