Skip to content

Commit

Permalink
fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yongjian_zhang committed Aug 14, 2024
1 parent a900d4e commit 108ae56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
32 changes: 2 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.9.3
hooks:
- id: isort
args:
- --check-only
- --diff
- repo: https://github.com/PyCQA/pylint
rev: v2.17.1
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [ python ]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.3.0
hooks:
- id: black
language_version: python3.10
language_version: python3
58 changes: 41 additions & 17 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,106 @@
from unittest.mock import MagicMock, patch

import cv2
import numpy as np
import pytest
from fastapi.testclient import TestClient

from api.docly_api import app
import pytest
from unittest.mock import patch, MagicMock
import numpy as np
import cv2

client = TestClient(app)


@pytest.fixture
def mock_cv2_imread():
with patch('cv2.imdecode') as mock:
with patch("cv2.imdecode") as mock:
mock.return_value = np.zeros((100, 100, 3), dtype=np.uint8)
yield mock


@pytest.fixture
def mock_ocr():
with patch('api.docly_api.OCR') as mock:
with patch("api.docly_api.OCR") as mock:
yield mock


@pytest.fixture
def mock_layout():
with patch('api.docly_api.Layout') as mock:
with patch("api.docly_api.Layout") as mock:
yield mock


@pytest.fixture
def mock_reading_order():
with patch('api.docly_api.ReadingOrder') as mock:
with patch("api.docly_api.ReadingOrder") as mock:
yield mock


@pytest.fixture
def mock_table_tsr():
with patch('api.docly_api.Table_TSR') as mock:
with patch("api.docly_api.Table_TSR") as mock:
yield mock


@pytest.fixture
def mock_yolov8():
with patch('api.docly_api.YOLOv8') as mock:
with patch("api.docly_api.YOLOv8") as mock:
yield mock


@pytest.fixture
def mock_detformula():
with patch('api.docly_api.DetFormula') as mock:
with patch("api.docly_api.DetFormula") as mock:
yield mock


@pytest.fixture
def mock_latexocr():
with patch('api.docly_api.LatexOCR') as mock:
with patch("api.docly_api.LatexOCR") as mock:
yield mock


@pytest.fixture
def mock_dbnet():
with patch('api.docly_api.DBNet') as mock:
with patch("api.docly_api.DBNet") as mock:
yield mock


@pytest.fixture
def mock_crnn():
with patch('api.docly_api.CRNN') as mock:
with patch("api.docly_api.CRNN") as mock:
yield mock


def test_ocr_endpoint(mock_ocr, mock_cv2_imread):
mock_ocr.return_value.return_value = "Mocked OCR result"
response = client.post("/ocr", files={"file": ("filename", b"file content", "image/jpeg")})
response = client.post(
"/ocr", files={"file": ("filename", b"file content", "image/jpeg")}
)
assert response.status_code == 200
assert response.json() == {"result": "Mocked OCR result"}


def test_reading_order_endpoint(mock_layout, mock_reading_order, mock_cv2_imread):
mock_layout.return_value.return_value = ([], [], [])
mock_reading_order.return_value.return_value = "Mocked reading order result"
response = client.post("/reading_order", files={"file": ("filename", b"file content", "image/jpeg")})
response = client.post(
"/reading_order", files={"file": ("filename", b"file content", "image/jpeg")}
)
assert response.status_code == 200
assert response.json() == {"result": "Mocked reading order result"}


def test_table_tsr_endpoint(mock_table_tsr, mock_cv2_imread):
mock_table_tsr.return_value.return_value = "Mocked table TSR result"
response = client.post("/table_tsr", files={"file": ("filename", b"file content", "image/jpeg")})
response = client.post(
"/table_tsr", files={"file": ("filename", b"file content", "image/jpeg")}
)
assert response.status_code == 200
assert response.json() == {"result": "Mocked table TSR result"}


def test_yolov8_endpoint(mock_yolov8, mock_cv2_imread):
mock_yolov8.return_value.return_value = "Mocked YOLOv8 result"


# Add more tests for other endpoints

0 comments on commit 108ae56

Please sign in to comment.