From 5a6a91b3d6cb13b18b91d66d398d2aa33e361b4c Mon Sep 17 00:00:00 2001 From: ross-p-smith Date: Mon, 29 Jan 2024 19:09:25 +0000 Subject: [PATCH] Move tests to root --- .github/workflows/unittests.yml | 25 +++++++++++++++++++ code/{utilities/tests => }/__init__.py | 0 code/requirements.txt | 2 +- tests/conftest.py | 0 tests/pytest.ini | 4 +++ .../tests => tests}/test_AzureBlobStorage.py | 3 ++- .../test_ContentSafetyChecker.py | 3 ++- .../tests => tests}/test_DocumentChunking.py | 5 ++-- .../tests => tests}/test_DocumentLoading.py | 8 +++--- .../tests => tests}/test_DocumentProcessor.py | 9 ++++--- .../tests => tests}/test_Orchestrator.py | 4 ++- .../tests => tests}/test_OutputParserTool.py | 4 +-- 12 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/unittests.yml rename code/{utilities/tests => }/__init__.py (100%) create mode 100644 tests/conftest.py create mode 100644 tests/pytest.ini rename {code/utilities/tests => tests}/test_AzureBlobStorage.py (79%) rename {code/utilities/tests => tests}/test_ContentSafetyChecker.py (77%) rename {code/utilities/tests => tests}/test_DocumentChunking.py (95%) rename {code/utilities/tests => tests}/test_DocumentLoading.py (83%) rename {code/utilities/tests => tests}/test_DocumentProcessor.py (83%) rename {code/utilities/tests => tests}/test_Orchestrator.py (79%) rename {code/utilities/tests => tests}/test_OutputParserTool.py (97%) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml new file mode 100644 index 000000000..ef153c6ba --- /dev/null +++ b/.github/workflows/unittests.yml @@ -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" diff --git a/code/utilities/tests/__init__.py b/code/__init__.py similarity index 100% rename from code/utilities/tests/__init__.py rename to code/__init__.py diff --git a/code/requirements.txt b/code/requirements.txt index 14c43aace..7cae9a282 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 000000000..c453246ed --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + unittest: Unit Tests (relatively fast) + azure: marks tests as extended (run less frequently, relatively slow) diff --git a/code/utilities/tests/test_AzureBlobStorage.py b/tests/test_AzureBlobStorage.py similarity index 79% rename from code/utilities/tests/test_AzureBlobStorage.py rename to tests/test_AzureBlobStorage.py index f3d3a4662..33f192a0b 100644 --- a/code/utilities/tests/test_AzureBlobStorage.py +++ b/tests/test_AzureBlobStorage.py @@ -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" diff --git a/code/utilities/tests/test_ContentSafetyChecker.py b/tests/test_ContentSafetyChecker.py similarity index 77% rename from code/utilities/tests/test_ContentSafetyChecker.py rename to tests/test_ContentSafetyChecker.py index 606b5d98f..a0978f95d 100644 --- a/code/utilities/tests/test_ContentSafetyChecker.py +++ b/tests/test_ContentSafetyChecker.py @@ -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() diff --git a/code/utilities/tests/test_DocumentChunking.py b/tests/test_DocumentChunking.py similarity index 95% rename from code/utilities/tests/test_DocumentChunking.py rename to tests/test_DocumentChunking.py index 2dda11c5a..9a9b4bbc4 100644 --- a/code/utilities/tests/test_DocumentChunking.py +++ b/tests/test_DocumentChunking.py @@ -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 = [ @@ -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}) diff --git a/code/utilities/tests/test_DocumentLoading.py b/tests/test_DocumentLoading.py similarity index 83% rename from code/utilities/tests/test_DocumentLoading.py rename to tests/test_DocumentLoading.py index 15eea5af4..07bc02770 100644 --- a/code/utilities/tests/test_DocumentLoading.py +++ b/tests/test_DocumentLoading.py @@ -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() @@ -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() @@ -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" diff --git a/code/utilities/tests/test_DocumentProcessor.py b/tests/test_DocumentProcessor.py similarity index 83% rename from code/utilities/tests/test_DocumentProcessor.py rename to tests/test_DocumentProcessor.py index c06100d31..b2943e269 100644 --- a/code/utilities/tests/test_DocumentProcessor.py +++ b/tests/test_DocumentProcessor.py @@ -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)) @@ -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)) @@ -23,6 +24,7 @@ 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)) @@ -30,6 +32,7 @@ def test_document_processor_web(): 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)) diff --git a/code/utilities/tests/test_Orchestrator.py b/tests/test_Orchestrator.py similarity index 79% rename from code/utilities/tests/test_Orchestrator.py rename to tests/test_Orchestrator.py index c9f88f63d..21e208d30 100644 --- a/code/utilities/tests/test_Orchestrator.py +++ b/tests/test_Orchestrator.py @@ -1,6 +1,7 @@ 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" @@ -8,6 +9,7 @@ def test_orchestrator_openai_function(): 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" diff --git a/code/utilities/tests/test_OutputParserTool.py b/tests/test_OutputParserTool.py similarity index 97% rename from code/utilities/tests/test_OutputParserTool.py rename to tests/test_OutputParserTool.py index 064bc8715..03ba08ac5 100644 --- a/code/utilities/tests/test_OutputParserTool.py +++ b/tests/test_OutputParserTool.py @@ -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():