fix(test): better test + cov

This commit is contained in:
Alex
2024-09-20 12:07:17 +01:00
parent a83e68815a
commit 68cc646a3e
2 changed files with 27 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest and generate coverage report
run: |
python -m pytest --cov=application --cov=scripts --cov=extensions --cov-report=xml
python -m pytest --cov=application --cov-report=xml
- name: Upload coverage reports to Codecov
if: github.event_name == 'pull_request' && matrix.python-version == '3.11'
uses: codecov/codecov-action@v3

View File

@@ -9,11 +9,33 @@ from application.core.settings import settings
def test_init_local_faiss_store_huggingface():
"""
Test that asserts that trying to initialize a FaissStore with
Test that asserts that initializing a FaissStore with
the huggingface sentence transformer below together with the
index.faiss file in the application/ folder results in a
dimension mismatch error.
"""
settings.EMBEDDINGS_NAME = "openai_text-embedding-ada-002"
with pytest.raises(ValueError):
FaissStore("application/", "", None)
import os
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.docstore.document import Document
from langchain_community.vectorstores import FAISS
# Ensure application directory exists
index_path = os.path.join("application")
os.makedirs(index_path, exist_ok=True)
# Create an index.faiss with a different embeddings dimension
# Use a different embedding model with a smaller dimension
other_embedding_model = "sentence-transformers/all-MiniLM-L6-v2" # Dimension 384
other_embeddings = HuggingFaceEmbeddings(model_name=other_embedding_model)
# Create some dummy documents
docs = [Document(page_content="Test document")]
# Create index using the other embeddings
other_docsearch = FAISS.from_documents(docs, other_embeddings)
# Save index to application/
other_docsearch.save_local(index_path)
# Now set the EMBEDDINGS_NAME to the one with a different dimension
settings.EMBEDDINGS_NAME = "huggingface_sentence-transformers/all-mpnet-base-v2" # Dimension 768
with pytest.raises(ValueError) as exc_info:
FaissStore("", None)
assert "Embedding dimension mismatch" in str(exc_info.value)