Skip to content

Refactor main function to reduce cyclomatic complexity #3

Refactor main function to reduce cyclomatic complexity

Refactor main function to reduce cyclomatic complexity #3

Workflow file for this run

name: CI
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y tesseract-ocr tesseract-ocr-eng
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: |
# Run flake8 to check code style and quality
flake8 main.py tests/ --count --select=E9,F63,F7,F82 --show-source --statistics
# Run full flake8 check but allow it to fail (for now)
flake8 main.py tests/ --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Test with unittest
run: |
python -m unittest discover tests/ -v
- name: Test application functionality
run: |
# Create a simple test image with text (using ImageMagick)
sudo apt-get install -y imagemagick
convert -size 300x100 xc:white -font DejaVu-Sans -pointsize 20 -fill black -annotate +10+30 'Test Image' test_image.png
# Test the application
python main.py -i test_image.png > output.txt
# Check if output contains expected text
if grep -q "Test" output.txt; then
echo "✅ Application test passed - OCR working correctly"
else
echo "❌ Application test failed - OCR not working"
cat output.txt
exit 1
fi
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run flake8 (strict)
run: |
flake8 main.py tests/ --max-line-length=120 --max-complexity=10
- name: Check for security issues with bandit
run: |
pip install bandit
bandit -r . -f json -o bandit-report.json || true
- name: Upload bandit report
uses: actions/upload-artifact@v4
if: always()
with:
name: bandit-security-report
path: bandit-report.json