Skip to content

Commit

Permalink
Most tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
adityabharadwaj198 committed Dec 2, 2024
1 parent 949b741 commit 3a0ad93
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@

@pytest.mark.marqo_version('2.0.0')
class TestAddDocuments(BaseCompatibilityTestCase):
structured_index_name = "add_doc_api_test_structured_index"
unstructured_index_name = "add_doc_api_test_unstructured_index"
structured_index_name = "test_add_doc_api_structured_index"
unstructured_index_name = "test_add_doc_api_unstructured_index"

indexes_to_test_on = [{
"indexName": structured_index_name,
"type": "structured",
"model": "sentence-transformers/all-MiniLM-L6-v2",
"normalizeEmbeddings": False,
"allFields": [
{"name": "title", "type": "text"},
{"name": "content", "type": "text"},
{"name": "int_field_1", "type": "int"},
{"name": "float_field_1", "type": "float"},
{"name": "long_field_1", "type": "long"},
{"name": "double_field_1", "type": "double"},
{"name": "array_int_field_1", "type": "array<int>"},
{"name": "array_float_field_1", "type": "array<float>"},
{"name": "array_long_field_1", "type": "array<long>"},
{"name": "array_double_field_1", "type": "array<double>"},
{"name": "custom_vector_field_1", "type": "custom_vector", "features": ["lexical_search", "filter"]},
{"name": "Title", "type": "text"},
{"name": "Description", "type": "text"},
{"name": "Genre", "type": "text"},
],
"tensorFields": ["title", "content", "custom_vector_field_1"],
"tensorFields": ["Title", "Description", "Genre"],
},
{
"indexName": unstructured_index_name,
Expand All @@ -36,7 +28,8 @@ class TestAddDocuments(BaseCompatibilityTestCase):
text_docs = [{
"Title": "The Travels of Marco Polo",
"Description": "A 13th-century travelogue describing the travels of Polo",
"Genre": "History"
"Genre": "History",
"_id": "article_602"
},
{
"Title": "Extravehicular Mobility Unit (EMU)",
Expand All @@ -63,8 +56,8 @@ def prepare(self):
if index.get("type") is not None and index.get('type') == 'structured':
self.client.index(index_name = index['indexName']).add_documents(documents = self.text_docs)
else:
self.client.index(index['indexName']).add_documents(documents = self.text_docs,
tensor_field = ["Description"])
self.client.index(index_name = index['indexName']).add_documents(documents = self.text_docs,
tensor_fields = ["Description", "Genre", "Title"])

self.logger.debug(f"Finished running prepare method for test case: {self.__class__.__name__}")
except Exception as e:
Expand All @@ -78,7 +71,12 @@ def prepare(self):

for doc in self.text_docs:
doc_id = doc['_id']
all_results[index_name][doc_id] = self.client.index(index_name).get_document(doc_id)
try:
all_results[index_name][doc_id] = self.client.index(index_name).get_document(doc_id)
except Exception as e:
self.logger.error(
f"Exception when getting documents with id: {doc_id} from index: {index_name}",
exc_info=True)

self.save_results_to_file(all_results)

Expand All @@ -90,7 +88,11 @@ def test_add_doc(self):

for doc in self.text_docs:
doc_id = doc['_id']
expected_doc = stored_results[index_name][doc_id]
try:
expected_doc = stored_results[index_name][doc_id]
except KeyError as e:
self.logger.error(f"The key {doc_id} doesn't exist in the stored results. Skipping the test for this document.")
continue
self.logger.debug(f"Printing expected doc {expected_doc}")
actual_doc = self.client.index(index_name).get_document(doc_id)
self.logger.debug(f"Printing actual doc {expected_doc}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from abc import abstractmethod, ABC
from pathlib import Path
from marqo_test import MarqoTestCase
from tests.compatibility_tests.base_test_case.marqo_test import MarqoTestCase


class BaseCompatibilityTestCase(MarqoTestCase, ABC):
Expand Down Expand Up @@ -63,8 +63,11 @@ def load_results_from_file(cls):
def delete_file(cls):
"""Delete the results file."""
filepath = cls.get_results_file_path()
filepath.unlink()
cls.logger.debug(f"Results file deleted: {filepath}")
if filepath.exists():
filepath.unlink()
cls.logger.debug(f"Results file deleted: {filepath}")
else:
cls.logger.debug(f"Not deleting, as the results file was never created in the first place.")

@abstractmethod
def prepare(self):
Expand Down
26 changes: 15 additions & 11 deletions tests/compatibility_tests/compatibility_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,9 @@ def run_prepare_mode(version_to_test_against: str):
# load_all_subclasses("tests.compatibility_tests.create_index")
# Get all subclasses of `BaseCompatibilityTestCase` that match the `version_to_test_against` criterion
# The below condition also checks if the test class is not marked to be skipped
logger.debug(f"Pritnign all subclasses {BaseCompatibilityTestCase.__subclasses__()}")
logger.debug(f"Printing all subclasses {BaseCompatibilityTestCase.__subclasses__()}")
for test_class in BaseCompatibilityTestCase.__subclasses__():
logger.info(f"=========================================================")
logger.debug(f"Test class {test_class.__name__}")
markers = getattr(test_class, "pytestmark", [])
# Check for specific markers
Expand All @@ -467,14 +468,17 @@ def run_prepare_mode(version_to_test_against: str):

marqo_version = marqo_version_marker.args[0]
logger.info(f"Detected marqo_version '{marqo_version}' for testcase: {test_class.__name__}")

if semver.VersionInfo.parse(marqo_version).compare(version_to_test_against) <= 0:
logger.info(f"Running prepare mode on testcase: {test_class.__name__} with version: {marqo_version}")
test_class.setUpClass() #setUpClass will be used to create Marqo client
test_instance = test_class()
test_instance.prepare() #Prepare method will be used to create index and add documents
else: # Skip the test if the version_to_test_against is greater than the version the test is marked
logger.info(f"Skipping testcase {test_class.__name__} with version {marqo_version} as it is greater than {version_to_test_against}")
try:
if semver.VersionInfo.parse(marqo_version).compare(version_to_test_against) <= 0:
logger.info(f"Running prepare mode on testcase: {test_class.__name__} with version: {marqo_version}")
test_class.setUpClass() #setUpClass will be used to create Marqo client
test_instance = test_class()
test_instance.prepare() #Prepare method will be used to create index and add documents
else: # Skip the test if the version_to_test_against is greater than the version the test is marked
logger.info(f"Skipping testcase {test_class.__name__} with version {marqo_version} as it is greater than {version_to_test_against}")
except Exception as e:
logger.error(f"Failed to run prepare mode on testcase: {test_class.__name__} with version: {marqo_version}, when test mode runs on this test case, it is expected to fail. The exception was {e}", exc_info=True)
logger.info(f"#############################################################")

def construct_pytest_arguments(version_to_test_against):
pytest_args = [
Expand Down Expand Up @@ -635,8 +639,8 @@ def backwards_compatibility_test(from_version: str, to_version: str, to_version_
logger.info("Calling stop_marqo_container with " + str(to_version))
stop_marqo_container(to_version)
# Clean up all containers at the end
# cleanup_containers()
# cleanup_volumes()
cleanup_containers()
cleanup_volumes()

def rollback_test(to_version: str, from_version: str, to_version_image: str):
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/compatibility_tests/create_index/test_create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ def test_expected_settings(self):
raise Exception(f"Exception when getting index settings for index {self.index_name}")

self.logger.debug(f"Expected settings: {expected_settings}")
self.logger.debug(f"Expected settings: {expected_settings}")
self.assertEqual(expected_settings, actual_settings)
self.assertEqual(expected_settings, actual_settings, f"Index settings do not match expected settings, expected {expected_settings}, but got {actual_settings}")
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,25 @@ class TestCreateStructuredIndex(BaseCompatibilityTestCase):

@classmethod
def tearDownClass(cls) -> None:
cls.indexes_to_delete = [index['indexName'] for index in cls.indexes_settings_to_test_on]
cls.indexes_to_delete = cls.indexes_to_test_on
super().tearDownClass()

@classmethod
def setUpClass(cls) -> None:
# cls.indexes_to_delete = [index['indexName'] for index in cls.indexes_to_test_on]
super().setUpClass()

def prepare(self):
self.logger.info(f"Creating indexes {self.indexes_settings_to_test_on}")
for index_settings in self.indexes_settings_to_test_on:
self.client.create_index("unstructured-index", settings_dict = index_settings)
for index_name, index_settings in zip(self.indexes_to_test_on, self.indexes_settings_to_test_on):
self.client.create_index(index_name, settings_dict = index_settings)

def test_expected_settings(self):
# expected_settings = self.indexes_settings_to_test_on
for index_name, expected_settings in zip(self.indexes_to_test_on, self.indexes_settings_to_test_on):
try:
actual_settings = self.client.index("unstructured-index").get_settings()
actual_settings = self.client.index(index_name).get_settings()
self.logger.debug(f"Printing actual_settings {actual_settings}")
self.logger.debug(f"Printing expected_settings {actual_settings}")
self.logger.debug(f"Printing expected_settings {expected_settings}")
except Exception as e:
self.logger.error(f"Exception while getting index settings {e}")
raise e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def prepare(self):
self.client.index(index_name = index['indexName']).add_documents(documents = self.text_docs)
else:
self.client.index(index['indexName']).add_documents(documents = self.text_docs,
tensor_field = ["Description"])
tensor_fields = ["Description"])

self.logger.debug(f"Finished running prepare method for test case: {self.__class__.__name__}")
except Exception as e:
Expand All @@ -70,7 +70,7 @@ def test_delete_document(self):
for index in self.indexes_to_test_on:
index_name = index['indexName']

result = self.client.index(index_name).delete_documents([])
result = self.client.index(index_name).delete_documents(["article_602", "article_591"])
self.logger.debug(f"Result: {result}")
assert result["index_name"] == index_name
assert result["type"] == "documentDeletion"
Expand Down
4 changes: 2 additions & 2 deletions tests/compatibility_tests/embed/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ def test_embed(self):


def _compare_embed_results(self, expected_result, actual_result):
self.assertEqual(expected_result.get("embeddings"), actual_result.get("embeddings"))
self.assertEqual(expected_result.get("content"), actual_result.get("content"))
self.assertEqual(expected_result.get("embeddings"), actual_result.get("embeddings"), f"Expected embeddings don't match actual embeddings. Expected {expected_result.get('embeddings')} but got {actual_result.get('embeddings')}")
self.assertEqual(expected_result.get("content"), actual_result.get("content"), f"Expected results don't match actual results. Expected {expected_result.get('content')} but got {actual_result.get('content')}")
4 changes: 2 additions & 2 deletions tests/compatibility_tests/search/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestSearch(BaseCompatibilityTestCase):
}
tensor_fields = ["multimodal_field", "text_field", "image_field"]
structured_index_metadata = {
"indexName": "structured-index-2-11",
"indexName": "test_search_api_structured_index",
"type": "structured",
"vectorNumericType": "float",
"model": image_model,
Expand Down Expand Up @@ -47,7 +47,7 @@ class TestSearch(BaseCompatibilityTestCase):
}

unstructured_index_metadata = {
"indexName": "unstructured-index-2-11",
"indexName": "test_search_api_unstructured_index",
"model": image_model,
"treatUrlsAndPointersAsImages": True,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestUpdateDocuments(BaseCompatibilityTestCase):
indexes_to_test_on = [{
"indexName": structured_index_name,
"type": "structured",
"all_fields": [
"allFields": [
{"name": "img", "type": "image_pointer"},
{"name": "title", "type": "text"},
{"name": "label", "type": "text", "features": ["filter"]},
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_update_doc(self):
self.logger.debug(f"Printing result {result}")
assert result["index_name"] == self.structured_index_name
assert len(result["items"]) == 2
assert result["errors"] == "false"
assert result["errors"] == False
for item in result["items"]:
if item["_id"] in {"1", "2"}:
assert item["status"] == 200

0 comments on commit 3a0ad93

Please sign in to comment.