Skip to content

Commit

Permalink
Move python tests to root (#242)
Browse files Browse the repository at this point in the history
* Move tests to root

* Move pytest ini
  • Loading branch information
ross-p-smith authored Jan 30, 2024
1 parent 31faf6f commit 446b09b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 14 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_call:

jobs:
test_package:
name: Unit Tests
runs-on: "ubuntu-20.04"
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: x64
- name: Install dependencies
run: |
pip install -r code/requirements.txt
- name: Run Python tests
run: python -m pytest --rootdir=code -m "not azure"
File renamed without changes.
2 changes: 1 addition & 1 deletion code/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ pandas==1.5.1
python-docx==1.1.0

# Add dev dependencies here - this will be refactored out by Poetry
pytest==7.4.4
pytest==8.0.0
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers =
unittest: Unit Tests (relatively fast)
azure: marks tests as extended (run less frequently, relatively slow)
Empty file added tests/conftest.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
from ..helpers.AzureBlobStorageHelper import AzureBlobStorageClient
from code.utilities.helpers.AzureBlobStorageHelper import AzureBlobStorageClient

@pytest.fixture
def blob_client():
return AzureBlobStorageClient()

@pytest.mark.azure("This test requires Azure Blob Storage")
def test_upload_and_download_file(blob_client):
# Upload a file
file_name = "test_file.txt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from ..tools.ContentSafetyChecker import ContentSafetyChecker
from code.utilities.tools.ContentSafetyChecker import ContentSafetyChecker

@pytest.mark.azure("This test requires Azure Content Safety configured")
def test_document_chunking_layout():

cut = ContentSafetyChecker()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from typing import List
from ..common.SourceDocument import SourceDocument
from ..helpers.DocumentChunkingHelper import DocumentChunking, ChunkingSettings, ChunkingStrategy
from code.utilities.common.SourceDocument import SourceDocument
from code.utilities.helpers.DocumentChunkingHelper import DocumentChunking, ChunkingSettings, ChunkingStrategy

# Create a sample document
documents = [
Expand All @@ -19,6 +19,7 @@
)
]

@pytest.mark.unittest("DocumentChunking")
def test_document_chunking_layout():
# Test layout chunking strategy
chunking = ChunkingSettings({"strategy": ChunkingStrategy.LAYOUT, "size": 10, "overlap": 5})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from typing import List
from ..helpers.DocumentLoadingHelper import DocumentLoading, LoadingSettings

from code.utilities.helpers.DocumentLoadingHelper import DocumentLoading, LoadingSettings

@pytest.mark.azure("This test requires Azure Document Intelligence configured")
def test_document_loading_layout():
# Azure Form Recognizer Layout
document_loading = DocumentLoading()
Expand All @@ -15,6 +15,7 @@ def test_document_loading_layout():
assert data[4].page_number == 4
assert data[4].source == url

@pytest.mark.azure("This test requires Azure Document Intelligence configured")
def test_document_loading_read():
# Azure Form Recognizer Read
document_loading = DocumentLoading()
Expand All @@ -34,7 +35,8 @@ def test_document_loading_web():
data = document_loading.load(url, LoadingSettings({"strategy": "web"}))
assert len(data) == 1
assert data[0].source == url


@pytest.mark.azure("This test requires Azure Document Intelligence configured")
def test_document_loading_docx():
document_loading = DocumentLoading()
url = "https://csciblob.blob.core.windows.net/rag-sol-acc/What is Azure OpenAI Service.docx"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest
from ..helpers.DocumentProcessorHelper import DocumentProcessor
from ..helpers.ConfigHelper import ConfigHelper
from code.utilities.helpers.DocumentProcessorHelper import DocumentProcessor
from code.utilities.helpers.ConfigHelper import ConfigHelper

document_url = "https://csciblob.blob.core.windows.net/rag-sol-acc/cognitive-services.pdf"
url = "https://learn.microsoft.com/en-us/azure/search/search-what-is-azure-search"
docx_url = "https://csciblob.blob.core.windows.net/rag-sol-acc/What is Azure OpenAI Service.docx"


@pytest.mark.azure("This test requires Azure")
def test_document_processor_layout():
document_processor = DocumentProcessor()
processors = list(filter(lambda x : x.document_type == 'pdf', ConfigHelper.get_active_config_or_default().document_processors))
Expand All @@ -15,6 +15,7 @@ def test_document_processor_layout():
assert len(keys) > 0


@pytest.mark.azure("This test requires Azure")
def test_document_processor_read():
document_processor = DocumentProcessor()
processors = list(filter(lambda x : x.document_type == 'pdf', ConfigHelper.get_active_config_or_default().document_processors))
Expand All @@ -23,13 +24,15 @@ def test_document_processor_read():
assert len(keys) > 0


@pytest.mark.azure("This test requires Azure")
def test_document_processor_web():
document_processor = DocumentProcessor()
processors = list(filter(lambda x : x.document_type == 'url', ConfigHelper.get_active_config_or_default().document_processors))
keys = document_processor.process(source_url= url, processors=processors)
print(keys)
assert len(keys) > 0

@pytest.mark.azure("This test requires Azure")
def test_document_processor_docx():
document_processor = DocumentProcessor()
processors = list(filter(lambda x : x.document_type == 'docx', ConfigHelper.get_active_config_or_default().document_processors))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest
from ..helpers.OrchestratorHelper import Orchestrator, OrchestrationSettings
from code.utilities.helpers.OrchestratorHelper import Orchestrator, OrchestrationSettings

@pytest.mark.azure("This test requires Azure Open AI configured")
def test_orchestrator_openai_function():
message_orchestrator = Orchestrator()
strategy = "openai_function"
messages = message_orchestrator.handle_message(user_message="What's Azure AI Search?", chat_history=[], conversation_id="test_openai_function", orchestrator = OrchestrationSettings({"strategy" : strategy}))
assert messages[-1]['role'] == 'assistant'
assert messages[-1]['content'] != ''

@pytest.mark.azure("This test requires Azure Open AI configured")
def test_orchestrator_langchain():
message_orchestrator = Orchestrator()
strategy = "langchain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from typing import List

from utilities.parser.OutputParserTool import OutputParserTool
from ..common.SourceDocument import SourceDocument
from code.utilities.parser.OutputParserTool import OutputParserTool
from code.utilities.common.SourceDocument import SourceDocument


def test_returns_parsed_messages():
Expand Down

0 comments on commit 446b09b

Please sign in to comment.