Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

test: guard the remaining optional-dependency tests on their backends (#2007)

Shubham Srivastava5dbb19ad8f23
diff --git a/tests/explorer/test_ontology_subissue3.py b/tests/explorer/test_ontology_subissue3.py
index 9dd8f41d..2cdc0b82 100644
--- a/tests/explorer/test_ontology_subissue3.py
+++ b/tests/explorer/test_ontology_subissue3.py
@@ -577,6 +577,9 @@ def test_shacl_validate_rejects_empty_turtle(client):
def test_shacl_validate_detects_missing_required_property(client):
+ # Needs the optional shacl extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("pyshacl")
graph = client.app.state.session.graph
onto_uri = "http://example.org/onto-a"
person_a = "http://example.org/onto-a#Person"
@@ -624,6 +627,9 @@ onto:PersonNameShape a sh:NodeShape ;
def test_shacl_validate_surfaces_warning_severity_results(client):
+ # Needs the optional shacl extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("pyshacl")
graph = client.app.state.session.graph
onto_uri = "http://example.org/onto-a"
person_a = "http://example.org/onto-a#Person"
diff --git a/tests/export/test_owl_exporter_generator_schema.py b/tests/export/test_owl_exporter_generator_schema.py
index d925fe6b..b99dd021 100644
--- a/tests/export/test_owl_exporter_generator_schema.py
+++ b/tests/export/test_owl_exporter_generator_schema.py
@@ -185,7 +185,9 @@ def test_a_class_without_any_identifier_is_skipped_not_emitted_as_empty():
def test_a_name_with_a_space_still_mints_a_valid_iri():
"""The name fallback pasted free text onto a base, producing `<... ...>`."""
- import pyoxigraph
+ # Needs the optional tripletstore-oxigraph extra; skip rather than fail on a
+ # core install.
+ pyoxigraph = pytest.importorskip("pyoxigraph")
ontology = {
"uri": "https://example.org/onto/",
diff --git a/tests/ingest/test_optional_imports.py b/tests/ingest/test_optional_imports.py
index c3446de5..1b4816c6 100644
--- a/tests/ingest/test_optional_imports.py
+++ b/tests/ingest/test_optional_imports.py
@@ -4,6 +4,8 @@ import sys
import textwrap
from pathlib import Path
+import pytest
+
REPO_ROOT = Path(__file__).resolve().parents[2]
@@ -70,6 +72,9 @@ print(PublicAPIIngestor.__name__, RESTIngestor.__name__, callable(ingest_public_
def test_public_api_ingestion_falls_back_without_defusedxml() -> None:
+ # Needs the optional documents extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("lxml")
result = _run_python_with_blocked_modules(
"""
from unittest.mock import MagicMock, patch
diff --git a/tests/ontology/test_notebook_14.py b/tests/ontology/test_notebook_14.py
index 941e45b4..92c2cc68 100644
--- a/tests/ontology/test_notebook_14.py
+++ b/tests/ontology/test_notebook_14.py
@@ -137,9 +137,13 @@ class TestNotebook14(unittest.TestCase):
self.assertEqual(len(messy_ontology['classes']), 2)
self.assertEqual(len(clean_ontology['classes']), 1)
+ # visualize_structure delegates to KGVisualizer, which holds its own
+ # module-level plotly reference, so it has to be mocked as well for the
+ # test to run without the optional viz extra.
+ @patch("semantica.visualization.kg_visualizer.go")
@patch("semantica.visualization.ontology_visualizer.make_subplots")
@patch("semantica.visualization.ontology_visualizer.go")
- def test_visualization(self, mock_go, mock_make_subplots):
+ def test_visualization(self, mock_go, mock_make_subplots, mock_kg_go):
"""Test OntologyVisualizer usage (mocking plotly)."""
viz = OntologyVisualizer()
ontology = self._run_full_pipeline()
diff --git a/tests/test_all_features.py b/tests/test_all_features.py
index 51a44658..05805827 100644
--- a/tests/test_all_features.py
+++ b/tests/test_all_features.py
@@ -45,6 +45,9 @@ class TestSemanticaFeatures(unittest.TestCase):
def test_03_model_switching(self):
"""Test dynamic model switching"""
+ # Needs the optional embeddings-local extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("sentence_transformers")
print("\nTesting Dynamic Model Switching...")
embedder = TextEmbedder(method="sentence_transformers")
info = embedder.get_model_info()
@@ -72,6 +75,9 @@ class TestSemanticaFeatures(unittest.TestCase):
def test_04_vector_store_basic(self):
"""Test VectorStore storage and search"""
+ # Needs the optional vectorstore-faiss extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("faiss")
print("\nTesting Vector Store Basic...")
store = VectorStore(backend="faiss", dimension=768)
@@ -90,6 +96,9 @@ class TestSemanticaFeatures(unittest.TestCase):
def test_05_faiss_store(self):
"""Test FAISSStore directly"""
+ # Needs the optional vectorstore-faiss extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("faiss")
print("\nTesting FAISSStore...")
store = FAISSStore(dimension=768)
index = store.create_index(index_type="hnsw", metric="L2", m=16)
diff --git a/tests/test_embedding_providers.py b/tests/test_embedding_providers.py
index 73d17e52..7f05f830 100644
--- a/tests/test_embedding_providers.py
+++ b/tests/test_embedding_providers.py
@@ -2,6 +2,7 @@
import sys
import os
import unittest
+import pytest
import numpy as np
# Add project root to path
@@ -11,6 +12,9 @@ from semantica.embeddings import TextEmbedder, EmbeddingGenerator
class TestEmbeddingProviders(unittest.TestCase):
def test_sentence_transformers_default(self):
+ # Needs the optional embeddings-local extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("sentence_transformers")
print("\nTesting Sentence Transformers (Default)...")
embedder = TextEmbedder(method="sentence_transformers")
text = "This is a test sentence."
diff --git a/tests/test_model_selection.py b/tests/test_model_selection.py
index 0f8484e0..9af33e39 100644
--- a/tests/test_model_selection.py
+++ b/tests/test_model_selection.py
@@ -2,6 +2,7 @@
import sys
import os
import unittest
+import pytest
import numpy as np
# Add project root to path
@@ -11,6 +12,13 @@ from semantica.embeddings import TextEmbedder, EmbeddingGenerator
class TestModelSelection(unittest.TestCase):
def test_dynamic_switching(self):
+ # Needs the optional embeddings-local extra; skip rather than fail on a
+ # core install. Both packages: the test switches to fastembed and
+ # asserts the switch took, and set_model() falls back silently instead
+ # of raising, so the surrounding `except ImportError` would not catch a
+ # missing fastembed.
+ pytest.importorskip("sentence_transformers")
+ pytest.importorskip("fastembed")
print("\nTesting Dynamic Model Switching...")
embedder = TextEmbedder(method="sentence_transformers")
info = embedder.get_model_info()
@@ -31,6 +39,13 @@ class TestModelSelection(unittest.TestCase):
print("FastEmbed not available for switching test")
def test_generator_switching(self):
+ # Needs the optional embeddings-local extra; skip rather than fail on a
+ # core install. Both packages: the test switches to fastembed and
+ # asserts the switch took, and set_model() falls back silently instead
+ # of raising, so the surrounding `except ImportError` would not catch a
+ # missing fastembed.
+ pytest.importorskip("sentence_transformers")
+ pytest.importorskip("fastembed")
print("\nTesting EmbeddingGenerator Switching...")
# Initialize with explicit method to ensure consistent starting state for test
generator = EmbeddingGenerator(text={"method": "sentence_transformers"})
diff --git a/tests/test_notebooks_repro.py b/tests/test_notebooks_repro.py
index ee1960eb..e3911a64 100644
--- a/tests/test_notebooks_repro.py
+++ b/tests/test_notebooks_repro.py
@@ -42,6 +42,9 @@ class TestNotebooks(unittest.TestCase):
self.fail(f"12_Embedding_Generation.ipynb failed: {e}")
def test_13_vector_store_basic(self):
+ # Needs the optional vectorstore-faiss extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("faiss")
print("\nTesting 13_Vector_Store.ipynb logic...")
try:
from semantica.vector_store import VectorStore
@@ -66,6 +69,9 @@ class TestNotebooks(unittest.TestCase):
self.fail(f"13_Vector_Store.ipynb failed: {e}")
def test_advanced_vector_store(self):
+ # Needs the optional vectorstore-faiss extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("faiss")
print("\nTesting Advanced_Vector_Store_and_Search.ipynb logic...")
try:
from semantica.vector_store import FAISSStore, HybridSearch, MetadataFilter, SearchRanker, NamespaceManager
diff --git a/tests/vector_store/test_qdrant_collection_search.py b/tests/vector_store/test_qdrant_collection_search.py
index 33265d88..b5398afb 100644
--- a/tests/vector_store/test_qdrant_collection_search.py
+++ b/tests/vector_store/test_qdrant_collection_search.py
@@ -280,6 +280,9 @@ def test_get_stats_uses_points_count_when_vectors_count_absent():
VectorParams instance), points_count is the correct substitute.
indexed_vectors_count must NOT be used: it counts only vectors
in optimised segments and is 0 for freshly-inserted data."""
+ # Needs the optional vectorstore-qdrant extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("qdrant_client")
from qdrant_client.models import VectorParams, Distance
store = QdrantStore()
store.client = MagicMock()
@@ -308,6 +311,9 @@ def test_get_stats_vectors_count_equals_points_count_when_vectors_count_absent()
vector collection the fallback is points_count, so both keys are equal.
indexed_vectors_count is intentionally absent from this mock to confirm
it is not required by the fallback path."""
+ # Needs the optional vectorstore-qdrant extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("qdrant_client")
from qdrant_client.models import VectorParams, Distance
store = QdrantStore()
store.client = MagicMock()
@@ -331,6 +337,9 @@ def test_get_stats_vectors_count_is_none_for_named_multi_vector_collection():
"""When vectors_count is absent and the collection uses named/multi vectors
(config.params.vectors is a dict), the total cannot be inferred and
vectors_count must be None rather than a misleading points_count value."""
+ # Needs the optional vectorstore-qdrant extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("qdrant_client")
from qdrant_client.models import VectorParams, Distance
store = QdrantStore()
store.client = MagicMock()
diff --git a/tests/visualization/test_visualization.py b/tests/visualization/test_visualization.py
index 8163354b..4a133570 100644
--- a/tests/visualization/test_visualization.py
+++ b/tests/visualization/test_visualization.py
@@ -1,4 +1,5 @@
import unittest
+import pytest
from unittest.mock import MagicMock, patch
from semantica.visualization.kg_visualizer import KGVisualizer
@@ -97,6 +98,9 @@ class TestVisualization(unittest.TestCase):
)
def test_class_property_matrix_marks_every_domain_of_a_multi_domain_property(self):
+ # Needs the optional viz extra; skip rather than fail on a
+ # core install.
+ pytest.importorskip("plotly")
viz = OntologyVisualizer()
ontology = {
"classes": [{"name": "Person"}, {"name": "Place"}],