fix: resolve CI import errors with proper test-only mocking

- Remove mock files from main semantica module (keep test environment clean)
- Enhance conftest.py with pre-emptive sys.modules mocking
- Create mock arrow_exporter module at runtime before imports
- Fix pyarrow 'pa' alias and schema mocking issues
- Ensure benchmark tests run without heavy dependencies
- All tests pass with zero changes to main codebase structure

Co-authored-by: ZohaibHassan16 <zohaib.hassan16@example.com>
Co-authored-by: KaifAhmad1 <kaifahmad087@gmail.com>
This commit is contained in:
KaifAhmad1
2026-02-07 17:23:57 +05:30
co-authored by ZohaibHassan16
parent 1ff05eef42
commit 3f12e78ca0
+20 -24
View File
@@ -183,30 +183,26 @@ if os.getenv("BENCHMARK_REAL_LIBS") != "1":
if "pa" not in sys.modules:
sys.modules["pa"] = RobustMock("pa")
# Pre-emptively mock the arrow_exporter module to prevent import errors
# This must happen before any semantica.export imports
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 or RobustMock("ENTITY_SCHEMA")
mock_arrow_module.RELATIONSHIP_SCHEMA = RELATIONSHIP_SCHEMA or RobustMock("RELATIONSHIP_SCHEMA")
mock_arrow_module.METADATA_SCHEMA = METADATA_SCHEMA or RobustMock("METADATA_SCHEMA")
mock_arrow_module.pa = RobustMock("pa")
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")
mock_arrow_module.pa = RobustMock("pa")
sys.modules["semantica.export.arrow_exporter"] = mock_arrow_module
# Pre-emptively create a mock arrow_exporter module to prevent import errors
# This must happen BEFORE any semantica.export imports
import types
mock_arrow_module = types.ModuleType('semantica.export.arrow_exporter')
# Create a mock ArrowExporter class with proper interface
class MockArrowExporter:
def __init__(self, *args, **kwargs):
pass
def __getattr__(self, name):
return lambda *args, **kwargs: f"Mock ArrowExporter.{name}"
mock_arrow_module.ArrowExporter = MockArrowExporter
mock_arrow_module.ENTITY_SCHEMA = RobustMock("ENTITY_SCHEMA")
mock_arrow_module.RELATIONSHIP_SCHEMA = RobustMock("RELATIONSHIP_SCHEMA")
mock_arrow_module.METADATA_SCHEMA = RobustMock("METADATA_SCHEMA")
mock_arrow_module.pa = RobustMock("pa")
# Inject the mock module into sys.modules
sys.modules["semantica.export.arrow_exporter"] = mock_arrow_module
# Infrastructure and Data Fixtures