Skip to content

Commit

Permalink
Merge pull request #69 from enoch3712/68-add-critical-tests-to-run-in…
Browse files Browse the repository at this point in the history
…-actions

workflow and pytests added for critical run
  • Loading branch information
enoch3712 authored Nov 14, 2024
2 parents 36eb78c + 262eb24 commit 08690be
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ jobs:
pip install poetry
poetry install
# - name: Run tests
# run: poetry run pytest
- name: Run critical tests
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: poetry run pytest tests/critical/ -v

- name: Build package
run: poetry build
Expand Down
45 changes: 45 additions & 0 deletions tests/critical/test_critical_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))

from dotenv import load_dotenv
from extract_thinker import Process
from extract_thinker.document_loader.document_loader_pypdf import DocumentLoaderPyPdf
from extract_thinker.extractor import Extractor
from extract_thinker.models.classification import Classification
from tests.models.invoice import InvoiceContract
from tests.models.driver_license import DriverLicense

load_dotenv()
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
INVOICE_PATH = os.path.join(CURRENT_DIR, '..', 'files', 'invoice.pdf')

def test_critical_classification():
"""Critical test for basic classification"""
# Setup
document_loader = DocumentLoaderPyPdf()
extractor = Extractor(document_loader)
extractor.load_llm("groq/llama-3.1-70b-versatile")

process = Process()
process.add_classify_extractor([[extractor]])

classifications = [
Classification(
name="Invoice",
description="This is an invoice document",
contract=InvoiceContract
),
Classification(
name="Driver License",
description="This is a driver license document",
contract=DriverLicense
)
]

# Act
result = process.classify(INVOICE_PATH, classifications)

# Assert
assert result is not None
assert result.name == "Invoice"
27 changes: 27 additions & 0 deletions tests/critical/test_critical_extraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))

from dotenv import load_dotenv
from extract_thinker import Extractor
from extract_thinker.document_loader.document_loader_pypdf import DocumentLoaderPyPdf
from tests.models.invoice import InvoiceContract

load_dotenv()
cwd = os.getcwd()

def test_critical_extract_with_pypdf():
"""Critical test for basic extraction functionality"""
test_file_path = os.path.join(cwd, "tests", "files", "invoice.pdf")

extractor = Extractor()
extractor.load_document_loader(DocumentLoaderPyPdf())
extractor.load_llm("groq/llama-3.1-70b-versatile")

result = extractor.extract(test_file_path, InvoiceContract)

assert result is not None
assert result.lines[0].description == "Consultation services"
assert result.lines[0].quantity == 3
assert result.lines[0].unit_price == 375
assert result.lines[0].amount == 1125

0 comments on commit 08690be

Please sign in to comment.