Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix: add comprehensive mocking for CI environment
KaifAhmad1e5e012cb5e21
diff --git a/benchmarks/conftest.py b/benchmarks/conftest.pyindex 269a8f70..82e33318 100644--- a/benchmarks/conftest.py+++ b/benchmarks/conftest.py@@ -182,6 +182,28 @@ if os.getenv("BENCHMARK_REAL_LIBS") != "1":# Special handling for 'pa' alias that's commonly used for pyarrowif "pa" not in sys.modules:sys.modules["pa"] = RobustMock("pa")++ # Mock missing modules that might be imported in the main codebase+ if "semantica.export.arrow_exporter" not in sys.modules:+ # Import the mock from benchmarks/export directory+ try:+ from benchmarks.export.arrow_exporter import ArrowExporter, ENTITY_SCHEMA, RELATIONSHIP_SCHEMA, METADATA_SCHEMA+ # Create a mock module with the actual mock classes+ import types+ mock_arrow_module = types.ModuleType('semantica.export.arrow_exporter')+ mock_arrow_module.ArrowExporter = ArrowExporter+ mock_arrow_module.ENTITY_SCHEMA = ENTITY_SCHEMA+ mock_arrow_module.RELATIONSHIP_SCHEMA = RELATIONSHIP_SCHEMA+ mock_arrow_module.METADATA_SCHEMA = METADATA_SCHEMA+ sys.modules["semantica.export.arrow_exporter"] = mock_arrow_module+ except ImportError:+ # Fallback to RobustMock if import fails+ mock_arrow_module = RobustMock("semantica.export.arrow_exporter")+ mock_arrow_module.ArrowExporter = create_mock_class("semantica.export.arrow_exporter.ArrowExporter")+ mock_arrow_module.ENTITY_SCHEMA = RobustMock("semantica.export.arrow_exporter.ENTITY_SCHEMA")+ mock_arrow_module.RELATIONSHIP_SCHEMA = RobustMock("semantica.export.arrow_exporter.RELATIONSHIP_SCHEMA")+ mock_arrow_module.METADATA_SCHEMA = RobustMock("semantica.export.arrow_exporter.METADATA_SCHEMA")+ sys.modules["semantica.export.arrow_exporter"] = mock_arrow_module# Infrastructure and Data Fixtures@@ -223,18 +245,32 @@ def kill_io_overhead():with patch("semantica.utils.logging.get_logger"), patch("semantica.utils.progress_tracker.get_progress_tracker", return_value=tracker):- patches = []- for mod_name, module in list(sys.modules.items()):- if mod_name.startswith("semantica.") and hasattr(- module, "get_progress_tracker"- ):- p = patch.object(module, "get_progress_tracker", return_value=tracker)- patches.append(p)- for p in patches:- p.start()- yield- for p in patches:- p.stop()+ # Patch the export module to handle missing ArrowExporter+ try:+ from benchmarks.export.arrow_exporter import ArrowExporter, ENTITY_SCHEMA, RELATIONSHIP_SCHEMA, METADATA_SCHEMA+ mock_arrow_module = RobustMock("semantica.export.arrow_exporter")+ mock_arrow_module.ArrowExporter = ArrowExporter+ mock_arrow_module.ENTITY_SCHEMA = ENTITY_SCHEMA+ mock_arrow_module.RELATIONSHIP_SCHEMA = RELATIONSHIP_SCHEMA+ mock_arrow_module.METADATA_SCHEMA = METADATA_SCHEMA+ except ImportError:+ mock_arrow_module = RobustMock("semantica.export.arrow_exporter")++ with patch.dict('sys.modules', {+ 'semantica.export.arrow_exporter': mock_arrow_module+ }):+ patches = []+ for mod_name, module in list(sys.modules.items()):+ if mod_name.startswith("semantica.") and hasattr(+ module, "get_progress_tracker"+ ):+ p = patch.object(module, "get_progress_tracker", return_value=tracker)+ patches.append(p)+ for p in patches:+ p.start()+ yield+ for p in patches:+ p.stop()class MockVectorStore:diff --git a/benchmarks/export/arrow_exporter.py b/benchmarks/export/arrow_exporter.pynew file mode 100644index 00000000..9b10e6ef--- /dev/null+++ b/benchmarks/export/arrow_exporter.py@@ -0,0 +1,69 @@+"""+Mock Arrow Exporter for Benchmark Testing++This module provides a mock implementation of the ArrowExporter to prevent+import errors during benchmark testing when PyArrow is not available in the CI environment.+"""++# Mock PyArrow import for CI compatibility+try:+ import pyarrow as pa+except ImportError:+ # Create a mock pa module for CI environment+ import types+ pa = types.ModuleType('pa')++ def mock_schema(*args, **kwargs):+ return types.SimpleNamespace()++ def mock_table(*args, **kwargs):+ return types.SimpleNamespace()++ def mock_array(*args, **kwargs):+ return types.SimpleNamespace()++ pa.schema = mock_schema+ pa.Table = mock_table+ pa.array = mock_array+ pa.RecordBatch = mock_table++# Mock schema definitions+ENTITY_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None+RELATIONSHIP_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None+METADATA_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None++class ArrowExporter:+ """+ Mock Arrow Exporter class for benchmark testing.++ This is a lightweight implementation that provides the same interface+ as the real ArrowExporter but doesn't require PyArrow to be installed.+ """++ def __init__(self, config=None):+ self.config = config+ self._tables = {}++ def export_entities(self, entities, output_path):+ """Mock export entities method."""+ return f"Mock exported {len(entities)} entities to {output_path}"++ def export_relationships(self, relationships, output_path):+ """Mock export relationships method."""+ return f"Mock exported {len(relationships)} relationships to {output_path}"++ def export_knowledge_graph(self, entities, relationships, output_path):+ """Mock export knowledge graph method."""+ return f"Mock exported knowledge graph to {output_path}"++ def to_arrow_table(self, data):+ """Mock conversion to Arrow table."""+ return f"Mock Arrow table with {len(data)} rows"++ def save_to_file(self, table, path):+ """Mock save to file method."""+ return f"Mock saved table to {path}"++ def batch_export(self, data_list, output_dir):+ """Mock batch export method."""+ return f"Mock batch exported {len(data_list)} items to {output_dir}"diff --git a/benchmarks/mock_arrow_exporter.py b/benchmarks/mock_arrow_exporter.pynew file mode 100644index 00000000..9b10e6ef--- /dev/null+++ b/benchmarks/mock_arrow_exporter.py@@ -0,0 +1,69 @@+"""+Mock Arrow Exporter for Benchmark Testing++This module provides a mock implementation of the ArrowExporter to prevent+import errors during benchmark testing when PyArrow is not available in the CI environment.+"""++# Mock PyArrow import for CI compatibility+try:+ import pyarrow as pa+except ImportError:+ # Create a mock pa module for CI environment+ import types+ pa = types.ModuleType('pa')++ def mock_schema(*args, **kwargs):+ return types.SimpleNamespace()++ def mock_table(*args, **kwargs):+ return types.SimpleNamespace()++ def mock_array(*args, **kwargs):+ return types.SimpleNamespace()++ pa.schema = mock_schema+ pa.Table = mock_table+ pa.array = mock_array+ pa.RecordBatch = mock_table++# Mock schema definitions+ENTITY_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None+RELATIONSHIP_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None+METADATA_SCHEMA = pa.schema([]) if hasattr(pa, 'schema') else None++class ArrowExporter:+ """+ Mock Arrow Exporter class for benchmark testing.++ This is a lightweight implementation that provides the same interface+ as the real ArrowExporter but doesn't require PyArrow to be installed.+ """++ def __init__(self, config=None):+ self.config = config+ self._tables = {}++ def export_entities(self, entities, output_path):+ """Mock export entities method."""+ return f"Mock exported {len(entities)} entities to {output_path}"++ def export_relationships(self, relationships, output_path):+ """Mock export relationships method."""+ return f"Mock exported {len(relationships)} relationships to {output_path}"++ def export_knowledge_graph(self, entities, relationships, output_path):+ """Mock export knowledge graph method."""+ return f"Mock exported knowledge graph to {output_path}"++ def to_arrow_table(self, data):+ """Mock conversion to Arrow table."""+ return f"Mock Arrow table with {len(data)} rows"++ def save_to_file(self, table, path):+ """Mock save to file method."""+ return f"Mock saved table to {path}"++ def batch_export(self, data_list, output_dir):+ """Mock batch export method."""+ return f"Mock batch exported {len(data_list)} items to {output_dir}"