Skip to content

Commit

Permalink
Add a simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed Oct 30, 2023
1 parent 2adf274 commit c44f8fa
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
83 changes: 83 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Test EasyOCR

on:
push:
branches:
- main
- ci
- release/*
- feature/*
tags:
- v*
paths-ignore:
- README*
pull_request:

jobs:
test_linux:
name: Test ${{ matrix.os }} with Python ${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
python: "3.11"
tesseract5: true
- os: ubuntu-latest
python: "3.12"
tesseract5: true
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0" # 0=all, needed for setuptools-scm to resolve version tags

- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: ${{ matrix.python }}
cache: "pip"

- name: Install Tesseract 5
if: matrix.tesseract5
run: |
sudo add-apt-repository -y ppa:alex-p/tesseract-ocr-devel
- name: Install common packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
curl \
ghostscript \
img2pdf \
libexempi8 \
libffi-dev \
libsm6 libxext6 libxrender-dev \
pngquant \
poppler-utils \
tesseract-ocr \
tesseract-ocr-deu \
tesseract-ocr-eng \
tesseract-ocr-osd \
unpaper \
zlib1g
- name: Install Python packages
run: |
python -m pip install --upgrade pip wheel
python -m pip install --prefer-binary .[test]
- name: Report versions
run: |
tesseract --version
gs --version
pngquant --version
unpaper --version
img2pdf --version
- name: Test
run: |
python -m pytest tests/
2 changes: 1 addition & 1 deletion ocrmypdf_easyocr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def add_options(parser):


class EasyOCREngine(OcrEngine):
"""Implements OCR with Tesseract."""
"""Implements OCR with EasyOCR."""

@staticmethod
def version():
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ocrmypdf = "ocrmypdf_easyocr"

[project.optional-dependencies]
dev = ["ruff>=0.0.272"]
test = [
"pytest>=6.2.5",
]

[build-system]
requires = ["setuptools"]
Expand Down
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MIT

from pathlib import Path

import pytest

TESTS_ROOT = Path(__file__).parent.resolve()
PROJECT_ROOT = TESTS_ROOT


@pytest.fixture(scope="session")
def resources() -> Path:
return Path(TESTS_ROOT) / "resources"


@pytest.fixture(scope="function")
def outdir(tmp_path) -> Path:
return tmp_path


@pytest.fixture(scope="function")
def outpdf(tmp_path) -> Path:
return tmp_path / "out.pdf"
Binary file added tests/resources/jbig2.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MIT

import ocrmypdf
import pikepdf
import pytest

import ocrmypdf_easyocr


def test_easyocr(resources, outpdf):
ocrmypdf.ocr(resources / "jbig2.pdf", outpdf)
assert outpdf.exists()

with pikepdf.open(outpdf) as pdf:
assert "EasyOCR" in str(pdf.docinfo["/Creator"])

0 comments on commit c44f8fa

Please sign in to comment.